Unverified Commit 8f58b775 authored by Amin Bandali's avatar Amin Bandali
Browse files

dialogs: use GtkFileChooserNative for remaining uses of GtkFileChooser

- accountcreationwizard, avatarmanipulation, chatview,
  newaccountsettingsview: reformatting and small stylistic changes.

- generalsettingsview, pluginsettingsview, video/video_widget:
  like the above, use GtkFileChooserNative for recent GTK versions and
  fall back onto GtkFileChooser for older versions.

Change-Id: Ic3abcd0f994939a7898c64f17a0f5c1a0c0e46b9
parent 369a862a
......@@ -871,40 +871,42 @@ choose_export_file(AccountCreationWizard *view)
auto alias = accountInfo.profileInfo.alias;
auto uri = alias.isEmpty() ? "export.gz" : alias + ".gz";
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native;
native = gtk_file_chooser_native_new(_("Save File"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view))),
action,
_("_Save"),
_("_Cancel"));
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(native), qUtf8Printable(uri));
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
g_object_unref(native);
#else
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new(_("Save File"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view))),
action,
_("_Cancel"),
GTK_RESPONSE_CANCEL,
_("_Save"),
GTK_RESPONSE_ACCEPT,
nullptr);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), qUtf8Printable(uri));
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}
gtk_widget_destroy(dialog);
#endif
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native = gtk_file_chooser_native_new(
_("Save File"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view))),
action,
_("_Save"),
_("_Cancel"));
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(native),
qUtf8Printable(uri));
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
g_object_unref(native);
#else
GtkWidget *dialog = gtk_file_chooser_dialog_new(
_("Save File"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view))),
action,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Save"), GTK_RESPONSE_ACCEPT,
nullptr);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),
qUtf8Printable(uri));
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}
gtk_widget_destroy(dialog);
#endif
if (!filename) return;
......
......@@ -427,54 +427,56 @@ choose_picture(AvatarManipulation *self)
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
GtkWidget *main_window = gtk_widget_get_toplevel(GTK_WIDGET(self));
auto preview = gtk_image_new();
GtkWidget *preview = gtk_image_new();
gint res;
gchar *filename = nullptr;
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native;
native = gtk_file_chooser_native_new (_("Open Avatar Image"),
GTK_WINDOW(main_window),
action,
_("_Open"),
_("_Cancel"));
/* add an image preview inside the file choose */
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER(native), preview);
g_signal_connect (GTK_FILE_CHOOSER(native), "update-preview", G_CALLBACK (update_preview_cb), preview);
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native = gtk_file_chooser_native_new(
_("Open Avatar Image"),
GTK_WINDOW(main_window),
action,
_("_Open"),
_("_Cancel"));
/* add an image preview inside the file choose */
gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(native),
preview);
g_signal_connect(GTK_FILE_CHOOSER(native), "update-preview",
G_CALLBACK(update_preview_cb), preview);
/* start the file chooser */
/* (blocks until the dialog is closed) */
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
/* start the file chooser */
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native)); /* blocks until the dialog is closed */
g_object_unref (native);
#else
GtkWidget *dialog = gtk_file_chooser_dialog_new(
_("Open Avatar Image"),
GTK_WINDOW(main_window),
action,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_ACCEPT,
NULL);
/* add an image preview inside the file choose */
gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog),
preview);
g_signal_connect (GTK_FILE_CHOOSER(dialog), "update-preview",
G_CALLBACK(update_preview_cb), preview);
/* start the file chooser */
/* (blocks until the dialog is closed) */
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (native));
}
g_object_unref (native);
#else
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new (_("Open Avatar Image"),
GTK_WINDOW(main_window),
action,
_("_Cancel"),
GTK_RESPONSE_CANCEL,
_("_Open"),
GTK_RESPONSE_ACCEPT,
NULL);
/* add an image preview inside the file choose */
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER(dialog), preview);
g_signal_connect (GTK_FILE_CHOOSER(dialog), "update-preview", G_CALLBACK (update_preview_cb), preview);
/* start the file chooser */
res = gtk_dialog_run (GTK_DIALOG(dialog)); /* blocks until the dialog is closed */
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (native));
}
gtk_widget_destroy(dialog);
#endif
gtk_widget_destroy(dialog);
#endif
if(filename) {
GError* error = nullptr; /* initialising to null avoid trouble... */
......
......@@ -277,40 +277,36 @@ file_to_manipulate(GtkWindow* top_window, bool send)
gint res;
gchar *filename = nullptr;
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native;
native = gtk_file_chooser_native_new(send? _("Send File") : _("Save File"),
top_window,
action,
send? _("_Open"): _("_Save"),
_("_Cancel"));
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native = gtk_file_chooser_native_new(
send ? _("Send File") : _("Save File"),
top_window,
action,
send ? _("_Open") : _("_Save"),
_("_Cancel"));
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG(native));
g_object_unref(native);
#else
GtkWidget *dialog = gtk_file_chooser_dialog_new(
send ? _("Send File") : _("Save File"),
top_window,
action,
_("_Cancel"), GTK_RESPONSE_CANCEL,
send ? _("_Open") : _("_Save"), GTK_RESPONSE_ACCEPT,
nullptr);
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
g_object_unref (native);
#else
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new(send? _("Send File") : _("Save File"),
top_window,
action,
_("_Cancel"),
GTK_RESPONSE_CANCEL,
send? _("_Open"): _("_Save"),
GTK_RESPONSE_ACCEPT,
nullptr);
res = gtk_dialog_run (GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}
gtk_widget_destroy (dialog);
#endif
gtk_widget_destroy(dialog);
#endif
return filename;
}
......
......@@ -228,22 +228,36 @@ choose_downloads_directory(GeneralSettingsView *self)
return;
}
GtkWidget *dialog = gtk_file_chooser_dialog_new (_("Choose download folder"),
GTK_WINDOW(priv->main_window_pnt),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
_("_Cancel"),
GTK_RESPONSE_CANCEL,
_("_Save"),
GTK_RESPONSE_ACCEPT,
NULL);
res = gtk_dialog_run (GTK_DIALOG(dialog));
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native = gtk_file_chooser_native_new(
_("Choose download folder"),
GTK_WINDOW(priv->main_window_pnt),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
_("_Save"),
_("_Cancel"));
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
g_object_unref(native);
#else
GtkWidget *dialog = gtk_file_chooser_dialog_new (
_("Choose download folder"),
GTK_WINDOW(priv->main_window_pnt),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Save"), GTK_RESPONSE_ACCEPT,
NULL);
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
auto chooser = GTK_FILE_CHOOSER(dialog);
filename = gtk_file_chooser_get_filename(chooser);
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}
gtk_widget_destroy (dialog);
#endif
if (!filename) return;
......
......@@ -909,39 +909,39 @@ choose_export_file(NewAccountSettingsView *view)
QString uri = alias.isEmpty() ? "export.gz" : alias + ".gz";
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native;
GtkFileChooserNative *native = gtk_file_chooser_native_new(
_("Save File"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view))),
action,
_("_Save"),
_("_Cancel"));
native = gtk_file_chooser_native_new(_("Save File"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view))),
action,
_("_Save"),
_("_Cancel"));
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(native),
qUtf8Printable(uri));
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(native), qUtf8Printable(uri));
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
g_object_unref (native);
g_object_unref(native);
#else
GtkWidget* dialog;
dialog = gtk_file_chooser_dialog_new(_("Save File"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view))),
action,
_("_Cancel"),
GTK_RESPONSE_CANCEL,
_("_Save"),
GTK_RESPONSE_ACCEPT,
nullptr);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), qUtf8Printable(uri));
res = gtk_dialog_run(GTK_DIALOG(dialog));
GtkWidget* dialog = gtk_file_chooser_dialog_new(
_("Save File"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view))),
action,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Save"), GTK_RESPONSE_ACCEPT,
nullptr);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),
qUtf8Printable(uri));
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}
gtk_widget_destroy(dialog);
#endif
......
......@@ -121,21 +121,37 @@ choose_jpl_file(PluginSettingsView *self)
gint res;
gchar* filename = nullptr;
GtkWidget *dialog = gtk_file_chooser_dialog_new (_("Choose plugin"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(self))),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Cancel"),
GTK_RESPONSE_CANCEL,
_("_Open"),
GTK_RESPONSE_ACCEPT,
NULL);
res = gtk_dialog_run (GTK_DIALOG(dialog));
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native = gtk_file_chooser_native_new(
_("Choose plugin"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(self))),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Open"),
_("_Cancel"));
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native));
}
g_object_unref(native);
#else
GtkWidget *dialog = gtk_file_chooser_dialog_new(
_("Choose plugin"),
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(self))),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_ACCEPT,
NULL);
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
auto chooser = GTK_FILE_CHOOSER(dialog);
filename = gtk_file_chooser_get_filename(chooser);
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}
gtk_widget_destroy (dialog);
gtk_widget_destroy(dialog);
#endif
if (!filename) return;
// install and load plugin
......
......@@ -803,17 +803,38 @@ switch_video_input_file(G_GNUC_UNUSED GtkWidget *item, GtkWidget *parent)
parent = gtk_widget_get_toplevel(GTK_WIDGET(parent));
}
gint res;
gchar *uri = nullptr;
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native = gtk_file_chooser_native_new(
_("Choose file"),
GTK_WINDOW(parent),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Open"),
_("_Cancel"));
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res == GTK_RESPONSE_ACCEPT) {
uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(native));
if (uri && priv->avModel_) {
priv->avModel_->setInputFile(uri, priv->remote->v_renderer->getId());
g_free(uri);
}
}
g_object_unref(native);
#else
GtkWidget *dialog = gtk_file_chooser_dialog_new(
"Choose File",
GTK_WINDOW(parent),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Open", GTK_RESPONSE_ACCEPT,
NULL);
_("Choose file"),
GTK_WINDOW(parent),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_ACCEPT,
NULL);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
gchar *uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
if (uri && priv->avModel_) {
priv->avModel_->setInputFile(uri, priv->remote->v_renderer->getId());
g_free(uri);
......@@ -821,6 +842,7 @@ switch_video_input_file(G_GNUC_UNUSED GtkWidget *item, GtkWidget *parent)
}
gtk_widget_destroy(dialog);
#endif
}
/*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment