Commit 369a862a authored by FuchtelJockel's avatar FuchtelJockel Committed by Amin Bandali
Browse files

dialogs: use GtkFileChooserNative instead of GtkFileChooser

add fallback for old GTK

Change-Id: I12eb968460dac3edcd2880d901d5984e903d2fb0
parent 49da15c7
......@@ -861,32 +861,50 @@ choose_export_file(AccountCreationWizard *view)
{
g_return_if_fail(IS_ACCOUNT_CREATION_WIZARD(view));
auto* priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view);
// Get preferred path
GtkWidget* dialog;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
gint res;
gchar* filename = nullptr;
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);
const auto& accountInfo = priv->accountModel_->getAccountInfo(priv->accountId);
auto alias = accountInfo.profileInfo.alias;
auto uri = alias.isEmpty() ? "export.gz" : alias + ".gz";
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), qUtf8Printable(uri));
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);
}
gtk_widget_destroy(dialog);
#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 (!filename) return;
......
......@@ -424,58 +424,83 @@ static void
choose_picture(AvatarManipulation *self)
{
AvatarManipulationPrivate *priv = AVATAR_MANIPULATION_GET_PRIVATE(self);
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
GtkWidget *main_window = gtk_widget_get_toplevel(GTK_WIDGET(self));
auto preview = gtk_image_new();
gint res;
gchar *filename = nullptr;
auto preview = gtk_image_new();
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native;
GtkWidget *main_window = gtk_widget_get_toplevel(GTK_WIDGET(self));
native = gtk_file_chooser_native_new (_("Open Avatar Image"),
GTK_WINDOW(main_window),
action,
_("_Open"),
_("_Cancel"));
auto 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) {
if(auto filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog))) {
GError* error = nullptr; /* initialising to null avoid trouble... */
auto picture = gdk_pixbuf_new_from_file_at_size (filename, VIDEO_WIDTH, VIDEO_HEIGHT, &error);
if (!error) {
/* reset crop area */
if (priv->crop_area)
gtk_container_remove(GTK_CONTAINER(priv->vbox_crop_area), priv->crop_area);
priv->crop_area = cc_crop_area_new();
gtk_widget_show(priv->crop_area);
gtk_box_pack_start(GTK_BOX(priv->vbox_crop_area), priv->crop_area, TRUE, TRUE, 0);
cc_crop_area_set_picture(CC_CROP_AREA(priv->crop_area), picture);
g_object_unref(picture);
set_state(self, AVATAR_MANIPULATION_STATE_EDIT);
} else {
g_warning("(choose_picture) failed to load pixbuf from file: %s", error->message);
g_error_free(error);
}
/* 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);
g_free(filename);
/* start the file chooser */
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native)); /* blocks until the dialog is closed */
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
if(filename) {
GError* error = nullptr; /* initialising to null avoid trouble... */
auto picture = gdk_pixbuf_new_from_file_at_size (filename, VIDEO_WIDTH, VIDEO_HEIGHT, &error);
if (!error) {
/* reset crop area */
if (priv->crop_area)
gtk_container_remove(GTK_CONTAINER(priv->vbox_crop_area), priv->crop_area);
priv->crop_area = cc_crop_area_new();
gtk_widget_show(priv->crop_area);
gtk_box_pack_start(GTK_BOX(priv->vbox_crop_area), priv->crop_area, TRUE, TRUE, 0);
cc_crop_area_set_picture(CC_CROP_AREA(priv->crop_area), picture);
g_object_unref(picture);
set_state(self, AVATAR_MANIPULATION_STATE_EDIT);
} else {
g_warning("(choose_picture) filename empty");
g_warning("(choose_picture) failed to load pixbuf from file: %s", error->message);
g_error_free(error);
}
}
gtk_widget_destroy(dialog);
g_free(filename);
} else {
g_warning("(choose_picture) filename empty");
}
}
static void
......
......@@ -273,27 +273,44 @@ send_text_clicked(ChatView *self, const std::string& body)
static gchar*
file_to_manipulate(GtkWindow* top_window, bool send)
{
GtkWidget* dialog;
GtkFileChooserAction action = send? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE;
gint res;
gchar* filename = nullptr;
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) {
auto chooser = GTK_FILE_CHOOSER(dialog);
filename = gtk_file_chooser_get_filename(chooser);
}
gtk_widget_destroy (dialog);
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"));
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(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
return filename;
}
......
......@@ -899,12 +899,34 @@ choose_export_file(NewAccountSettingsView *view)
{
g_return_if_fail(IS_NEW_ACCOUNT_SETTINGS_VIEW(view));
auto* priv = NEW_ACCOUNT_SETTINGS_VIEW_GET_PRIVATE(view);
// Get preferred path
GtkWidget* dialog;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
gint res;
gchar* filename = nullptr;
QString alias = (*priv->accountInfo_)->profileInfo.alias;
QString 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,
......@@ -914,16 +936,14 @@ choose_export_file(NewAccountSettingsView *view)
GTK_RESPONSE_ACCEPT,
nullptr);
QString alias = (*priv->accountInfo_)->profileInfo.alias;
QString uri = alias.isEmpty()? "export.gz" : alias + ".gz";
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), qUtf8Printable(uri));
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;
......
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