Source

NPAPI-chrome-file-api / X11 / DialogManagerX11.cpp~

Full commit
#include <string>
#include <boost/thread.hpp>

#include "DialogManagerX11.h"
#include "BrowserHost.h"
#include "PluginWindowX11.h"

DialogManager* DialogManager::get()
{
    static DialogManagerX11 inst;
    return &inst;
}

void DialogManagerX11::OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb)
{
    FB::PluginWindowX11* x11Win = dynamic_cast<FB::PluginWindowX11*>(win);
    GdkNativeWindow nativeWin = x11Win->getBrowserWindow();
    GtkWindow* gtkWin = gdk_window_lookup(nativeWin);
    host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerX11>(), boost::bind(&DialogManagerX11::_showFolderDialog, this, gtkWin, cb));
}

void DialogManagerX11::_showFolderDialog(GtkWindow* win, const PathCallback& cb)
{
    std::string out;
    GtkWidget *dialog;
    dialog = gtk_file_chooser_dialog_new ("Open File",
				      win,
				      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				      NULL);
    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
    {
        char *filename;
        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
        out = filename;
        g_free (filename);
    }
    gtk_widget_destroy (dialog);
    cb(out);
}