From 948fc073bb7f343fcaf591a384a5f0947a573616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Canek=20Pel=C3=A1ez=20Vald=C3=A9s?= Date: Thu, 21 Feb 2019 23:35:51 -0600 Subject: [PATCH] Warning dialogs. --- data/mlm.gresource.xml | 1 + data/warning.ui | 65 +++++++++++++++++++++++++ meson.build | 3 +- src/application/application-window.vala | 13 ++++- src/application/application.vala | 2 +- src/application/shortcuts-window.vala | 10 +++- src/application/warning-dialog.vala | 40 +++++++++++++++ 7 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 data/warning.ui create mode 100644 src/application/warning-dialog.vala diff --git a/data/mlm.gresource.xml b/data/mlm.gresource.xml index b24f07a..08667b5 100644 --- a/data/mlm.gresource.xml +++ b/data/mlm.gresource.xml @@ -5,5 +5,6 @@ mlm.ui mlm.svg shortcuts.ui + warning.ui diff --git a/data/warning.ui b/data/warning.ui new file mode 100644 index 0000000..3bac79d --- /dev/null +++ b/data/warning.ui @@ -0,0 +1,65 @@ + + + + + diff --git a/meson.build b/meson.build index 398b1ed..28c36c6 100644 --- a/meson.build +++ b/meson.build @@ -135,7 +135,8 @@ mlm_gui_sources = [ 'src/application/main.vala', 'src/application/media.vala', 'src/application/player.vala', - 'src/application/shortcuts-window.vala' + 'src/application/shortcuts-window.vala', + 'src/application/warning-dialog.vala' ] mlm_gui_dependencies = [ diff --git a/src/application/application-window.vala b/src/application/application-window.vala index 841272d..e8ba24e 100644 --- a/src/application/application-window.vala +++ b/src/application/application-window.vala @@ -417,7 +417,9 @@ namespace MLM { FileUtils.get_data(fn, out data); return data; } catch (GLib.FileError fe) { - warning(_("There was an error loading image '%s'").printf(fn)); + var bn = GLib.Path.get_basename(fn); + var m = _("There was an error loading image '%s'").printf(bn); + show_warning(m); } return null; } @@ -447,12 +449,19 @@ namespace MLM { (int)(pixbuf.height*scale), Gdk.InterpType.BILINEAR); } catch (GLib.Error e) { - warning(_("Could not set pixbuf from data.")); + show_warning(_("Could not set pixbuf from data.")); set_default_image(image); return; } save_button.sensitive = true; image.set_from_pixbuf(thumb); } + + /* Shows a warning dialog. */ + private void show_warning(string message) { + var dialog = new WarningDialog(this, message); + dialog.run(); + dialog.destroy(); + } } } diff --git a/src/application/application.vala b/src/application/application.vala index 0be1967..a997fb3 100644 --- a/src/application/application.vala +++ b/src/application/application.vala @@ -277,7 +277,7 @@ namespace MLM { /* The shortcuts action. */ private void shortcuts() { if (shortcuts_window == null) - shortcuts_window = new ShortcutsWindow(); + shortcuts_window = new ShortcutsWindow(window); shortcuts_window.show_all(); } diff --git a/src/application/shortcuts-window.vala b/src/application/shortcuts-window.vala index 96c5ce3..f8919ed 100644 --- a/src/application/shortcuts-window.vala +++ b/src/application/shortcuts-window.vala @@ -23,5 +23,13 @@ namespace MLM { * Class for shortcuts windows. */ [GtkTemplate (ui = "/mx/unam/MLM/shortcuts.ui")] - public class ShortcutsWindow : Gtk.ShortcutsWindow {} + public class ShortcutsWindow : Gtk.ShortcutsWindow { + + /** + * Initializes a shortcuts window. + */ + public ShortcutsWindow(Gtk.Window window) { + transient_for = window; + } + } } diff --git a/src/application/warning-dialog.vala b/src/application/warning-dialog.vala new file mode 100644 index 0000000..098f7da --- /dev/null +++ b/src/application/warning-dialog.vala @@ -0,0 +1,40 @@ +/* + * This file is part of mlm. + * + * Copyright © 2016-2018 Canek Peláez Valdés + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +namespace MLM { + + /** + * Class for warning dialogs. + */ + [GtkTemplate (ui = "/mx/unam/MLM/warning.ui")] + public class WarningDialog : Gtk.Dialog { + + [GtkChild] + private Gtk.Label message_label; + + /** + * Initializes a shortcuts window. + */ + public WarningDialog(Gtk.Window window, string message) { + GLib.Object(use_header_bar: 1); + transient_for = window; + message_label.label = message; + } + } +} -- GitLab