summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2023-02-20 21:29:02 +0100
committerNiels De Graef <nielsdegraef@gmail.com>2023-02-20 21:32:32 +0100
commit5d5c20047f26819d0049c0d88b51036fa32daaaa (patch)
tree9597c1d29f8ae5ba3dcef24bfa5aa81722b9060c
parentb918da4c569fe40e8cd4afdeb4dcaf5f34a6785c (diff)
downloadgnome-contacts-nielsdg/no-more-gtkdialog.tar.gz
Stop using GtkDialognielsdg/no-more-gtkdialog
GtkDialog is going to be deprecated in the next version of GTK, so stop using it upfront to avoid the deprecation warnings.
-rw-r--r--data/contacts.gresource.xml1
-rw-r--r--data/ui/contacts-avatar-selector.ui61
-rw-r--r--data/ui/contacts-crop-dialog.ui59
-rw-r--r--data/ui/contacts-linked-personas-dialog.ui50
-rw-r--r--src/contacts-avatar-selector.vala56
-rw-r--r--src/contacts-contact-editor.vala61
-rw-r--r--src/contacts-crop-dialog.vala23
-rw-r--r--src/contacts-linked-personas-dialog.vala93
-rw-r--r--src/meson.build1
9 files changed, 155 insertions, 250 deletions
diff --git a/data/contacts.gresource.xml b/data/contacts.gresource.xml
index 3daf6d6..3d46685 100644
--- a/data/contacts.gresource.xml
+++ b/data/contacts.gresource.xml
@@ -20,7 +20,6 @@
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-crop-dialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-editor-menu.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-link-suggestion-grid.ui</file>
- <file compressed="true" preprocess="xml-stripblanks">ui/contacts-linked-personas-dialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-main-window.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-preferences-window.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-qr-code-dialog.ui</file>
diff --git a/data/ui/contacts-avatar-selector.ui b/data/ui/contacts-avatar-selector.ui
index 5f34fe9..f09c6ec 100644
--- a/data/ui/contacts-avatar-selector.ui
+++ b/data/ui/contacts-avatar-selector.ui
@@ -1,32 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="ContactsAvatarSelector" parent="GtkDialog">
+ <template class="ContactsAvatarSelector" parent="GtkWindow">
<property name="modal">True</property>
<property name="default_width">400</property>
<property name="default_height">400</property>
- <property name="title" translatable="yes">Select a new avatar</property>
+ <binding name="title">
+ <lookup name="title">title_widget</lookup>
+ </binding>
- <child type="action">
- <object class="GtkButton" id="cancel_button">
- <property name="label" translatable="yes">Cancel</property>
- <property name="receives_default">True</property>
+ <child>
+ <object class='GtkShortcutController'>
+ <child>
+ <object class='GtkShortcut'>
+ <property name='trigger'>Escape</property>
+ <property name='action'>action(window.close)</property>
+ </object>
+ </child>
</object>
</child>
- <child type="action">
- <object class="GtkButton" id="done_button">
- <property name="label" translatable="yes">Done</property>
- <style>
- <class name="suggested-action"/>
- </style>
+
+ <child type="titlebar">
+ <object class="GtkHeaderBar">
+ <property name="show-title-buttons">False</property>
+
+ <child type="start">
+ <object class="GtkButton">
+ <property name="label" translatable="yes">_Cancel</property>
+ <property name="use-underline">True</property>
+ <property name="receives-default">True</property>
+ <property name="action-name">window.close</property>
+ </object>
+ </child>
+
+ <property name="title-widget">
+ <object class="AdwWindowTitle" id="title_widget">
+ <property name="title" translatable="yes">Select a new avatar</property>
+ </object>
+ </property>
+
+ <child type="end">
+ <object class="GtkButton" id="done_button">
+ <property name="label" translatable="yes">_Done</property>
+ <property name="use-underline">True</property>
+ <property name="action-name">set-avatar</property>
+ <style>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ </child>
</object>
</child>
- <action-widgets>
- <action-widget response="cancel">cancel_button</action-widget>
- <action-widget response="accept" default="true">done_button</action-widget>
- </action-widgets>
-
- <child internal-child="content_area">
+ <child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
diff --git a/data/ui/contacts-crop-dialog.ui b/data/ui/contacts-crop-dialog.ui
index 2a79536..e691477 100644
--- a/data/ui/contacts-crop-dialog.ui
+++ b/data/ui/contacts-crop-dialog.ui
@@ -1,33 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="ContactsCropDialog" parent="GtkDialog">
+ <template class="ContactsCropDialog" parent="GtkWindow">
<property name="modal">True</property>
<property name="default-width">400</property>
<property name="default-height">400</property>
- <property name="destroy-with-parent">True</property>
- <property name="title"></property>
- <child type="action">
- <object class="GtkButton" id="cancel_button">
- <property name="label" translatable="yes">Cancel</property>
+ <child>
+ <object class='GtkShortcutController'>
+ <child>
+ <object class='GtkShortcut'>
+ <property name='trigger'>Escape</property>
+ <property name='action'>action(window.close)</property>
+ </object>
+ </child>
</object>
</child>
- <child type="action">
- <object class="GtkButton" id="done_button">
- <property name="label" translatable="yes">Done</property>
- <style>
- <class name="suggested-action"/>
- </style>
- </object>
- </child>
- <action-widgets>
- <action-widget response="cancel">cancel_button</action-widget>
- <action-widget response="accept" default="true">done_button</action-widget>
- </action-widgets>
- <child internal-child="content_area">
- <object class="GtkBox" id="box">
- <property name="orientation">vertical</property>
+ <child type="titlebar">
+ <object class="GtkHeaderBar">
+ <property name="show-title-buttons">False</property>
+
+ <child type="start">
+ <object class="GtkButton">
+ <property name="label" translatable="yes">_Cancel</property>
+ <property name="use-underline">True</property>
+ <property name="receives-default">True</property>
+ <property name="action-name">window.close</property>
+ </object>
+ </child>
+
+ <property name="title-widget">
+ <object class="AdwWindowTitle" id="title_widget">
+ <property name="title"></property>
+ </object>
+ </property>
+
+ <child type="end">
+ <object class="GtkButton" id="done_button">
+ <property name="label" translatable="yes">_Done</property>
+ <property name="use-underline">True</property>
+ <property name="action-name">crop</property>
+ <style>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ </child>
</object>
</child>
</template>
diff --git a/data/ui/contacts-linked-personas-dialog.ui b/data/ui/contacts-linked-personas-dialog.ui
deleted file mode 100644
index e783d52..0000000
--- a/data/ui/contacts-linked-personas-dialog.ui
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<interface>
- <template class="ContactsLinkedPersonasDialog" parent="GtkDialog">
- <property name="modal">True</property>
- <property name="default_width">600</property>
- <property name="default_height">400</property>
- <child type="titlebar">
- <object class="GtkHeaderBar">
- <property name="subtitle" translatable="yes">Linked Accounts</property>
- </object>
- </child>
- <child internal-child="vbox">
- <object class="GtkBox">
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkGrid">
- <property name="orientation">vertical</property>
- <property name="column_spacing">8</property>
- <property name="row_spacing">12</property>
- <child>
- <object class="GtkScrolledWindow">
- <property name="hscrollbar_policy">never</property>
- <property name="vscrollbar_policy">automatic</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</property>
- <property name="shadow_type">in</property>
- <child>
- <object class="GtkViewport">
- <property name="scroll-to-focus">True</property>
- <child>
- <object class="GtkListBox" id="linked_accounts_view">
- <property name="selection_mode">none</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkLabel">
- <property name="halign">center</property>
- <property name="label" translatable="yes">You can link contacts by selecting them from the contacts list</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- </template>
-</interface>
diff --git a/src/contacts-avatar-selector.vala b/src/contacts-avatar-selector.vala
index 4660351..e9740c8 100644
--- a/src/contacts-avatar-selector.vala
+++ b/src/contacts-avatar-selector.vala
@@ -68,7 +68,7 @@ private class Contacts.Thumbnail : Gtk.FlowBoxChild {
* After a user has initially chosen an avatar, we provide a cropping tool.
*/
[GtkTemplate (ui = "/org/gnome/Contacts/ui/contacts-avatar-selector.ui")]
-public class Contacts.AvatarSelector : Gtk.Dialog {
+public class Contacts.AvatarSelector : Gtk.Window {
const string AVATAR_BUTTON_CSS_NAME = "avatar-button";
@@ -88,8 +88,12 @@ public class Contacts.AvatarSelector : Gtk.Dialog {
private set { this._selected_avatar = value; }
}
+ static construct {
+ install_action ("set-avatar", null, (Gtk.WidgetActionActivateFunc) on_set_avatar);
+ }
+
public AvatarSelector (Contact contact, Gtk.Window? window = null) {
- Object (contact: contact, transient_for: window, use_header_bar: 1);
+ Object (contact: contact, transient_for: window);
this.thumbnail_grid.selected_children_changed.connect (on_thumbnails_selected);
this.thumbnail_grid.child_activated.connect (on_thumbnail_activated);
@@ -112,7 +116,7 @@ public class Contacts.AvatarSelector : Gtk.Dialog {
Gtk.FlowBoxChild child) {
unowned var thumbnail = (Thumbnail) child;
this.selected_avatar = thumbnail.source_pixbuf;
- this.response (Gtk.ResponseType.ACCEPT);
+ activate_action_variant ("set-avatar", null);
}
private async void setup_camera_portal () {
@@ -148,16 +152,29 @@ public class Contacts.AvatarSelector : Gtk.Dialog {
}
/** Sets the selected avatar on the contact (it does _not_ save it) */
- public void set_avatar_on_contact () throws GLib.Error {
- uint8[] buffer;
- this.selected_avatar.save_to_buffer (out buffer, "png", null);
- var icon = new BytesIcon (new Bytes (buffer));
-
- // Save into the most relevant avatar
- var avatar_chunk = this.contact.get_most_relevant_chunk ("avatar", true);
- if (avatar_chunk == null)
- avatar_chunk = this.contact.create_chunk ("avatar", null);
- ((AvatarChunk) avatar_chunk).avatar = icon;
+ private void on_set_avatar (string action_name, Variant? param) {
+ debug ("Setting avatar");
+ try {
+ uint8[] buffer;
+ this.selected_avatar.save_to_buffer (out buffer, "png", null);
+ var icon = new BytesIcon (new Bytes (buffer));
+
+ // Save into the most relevant avatar
+ var avatar_chunk = this.contact.get_most_relevant_chunk ("avatar", true);
+ if (avatar_chunk == null)
+ avatar_chunk = this.contact.create_chunk ("avatar", null);
+ ((AvatarChunk) avatar_chunk).avatar = icon;
+ destroy ();
+ } catch (Error e) {
+ destroy ();
+
+ warning ("Failed to set avatar: %s", e.message);
+ var dialog = new Adw.MessageDialog (this.transient_for,
+ null,
+ _("Failed to set avatar"));
+ dialog.add_response ("close", _("_Close"));
+ dialog.show ();
+ }
}
private void update_thumbnail_grid () {
@@ -218,17 +235,14 @@ public class Contacts.AvatarSelector : Gtk.Dialog {
if (pixbuf.get_width () > MAIN_SIZE || pixbuf.get_height () > MAIN_SIZE) {
var dialog = new CropDialog.for_pixbuf (pixbuf,
get_root () as Gtk.Window);
- dialog.response.connect ((response) => {
- if (response == Gtk.ResponseType.ACCEPT) {
- this.selected_avatar = dialog.create_pixbuf ();
- this.response (Gtk.ResponseType.ACCEPT);
- }
- dialog.destroy ();
+ dialog.cropped.connect ((pixbuf) => {
+ this.selected_avatar = pixbuf;
+ activate_action_variant ("set-avatar", null);
});
- dialog.show ();
+ dialog.present ();
} else {
this.selected_avatar = pixbuf;
- this.response (Gtk.ResponseType.ACCEPT);
+ activate_action_variant ("set-avatar", null);
}
} catch (GLib.Error e) {
warning ("Failed to set avatar: %s", e.message);
diff --git a/src/contacts-contact-editor.vala b/src/contacts-contact-editor.vala
index b90384d..26c5730 100644
--- a/src/contacts-contact-editor.vala
+++ b/src/contacts-contact-editor.vala
@@ -104,23 +104,7 @@ public class Contacts.ContactEditor : Gtk.Widget {
// Show the avatar popover when the avatar is clicked
private void on_avatar_button_clicked (Gtk.Button avatar_button) {
var avatar_selector = new AvatarSelector (this.contact, get_root () as Gtk.Window);
- avatar_selector.response.connect ((response) => {
- if (response == Gtk.ResponseType.ACCEPT) {
- try {
- avatar_selector.set_avatar_on_contact ();
- } catch (Error e) {
- warning ("Failed to set avatar: %s", e.message);
- var dialog = new Adw.MessageDialog (get_root () as Gtk.Window,
- null,
- _("Failed to set avatar."));
- dialog.add_response ("close", _("_Close"));
- dialog.default_response = "close";
- dialog.show();
- }
- }
- avatar_selector.destroy ();
- });
- avatar_selector.show ();
+ avatar_selector.present ();
}
// Creates the big name entry on the top
@@ -690,7 +674,7 @@ public class Contacts.ContactEditorProperty : Gtk.Widget {
}
}
-public class Contacts.BirthdayEditor : Gtk.Dialog {
+public class Contacts.BirthdayEditor : Gtk.Window {
private unowned Gtk.SpinButton day_spin;
private unowned Gtk.ComboBoxText month_combo;
@@ -700,13 +684,17 @@ public class Contacts.BirthdayEditor : Gtk.Dialog {
public signal void changed ();
+ static construct {
+ add_binding_action (Gdk.Key.Escape, 0, "window.close", null);
+ }
+
construct {
// The grid that will contain the Y/M/D fields
var grid = new Gtk.Grid ();
grid.column_spacing = 12;
grid.row_spacing = 12;
grid.add_css_class ("contacts-editor-birthday");
- ((Gtk.Box) this.get_content_area ()).append (grid);
+ this.child = grid;
// Day
var d_spin = new Gtk.SpinButton.with_range (1.0, 31.0, 1.0);
@@ -744,27 +732,28 @@ public class Contacts.BirthdayEditor : Gtk.Dialog {
grid.attach (year, 0, 2);
grid.attach (year_spin, 1, 2);
- this.title = _("Change Birthday");
- add_buttons (_("Set"), Gtk.ResponseType.OK,
- _("Cancel"), Gtk.ResponseType.CANCEL,
- null);
- var ok_button = this.get_widget_for_response (Gtk.ResponseType.OK);
+ // Headerbar
+ var titlebar = new Gtk.HeaderBar ();
+ this.titlebar = titlebar;
+ titlebar.title_widget = new Adw.WindowTitle (_("Change Birthday"), "");
+ titlebar.show_title_buttons = false;
+
+ var cancel_button = new Gtk.Button.with_mnemonic (_("_Cancel"));
+ cancel_button.action_name = "window.close";
+ titlebar.pack_start (cancel_button);
+
+ var ok_button = new Gtk.Button.with_mnemonic (_("_Set"));
ok_button.add_css_class ("suggested-action");
- this.response.connect ((id) => {
- switch (id) {
- case Gtk.ResponseType.OK:
- this.is_set = true;
- changed ();
- break;
- case Gtk.ResponseType.CANCEL:
- break;
- }
- this.destroy ();
+ ok_button.clicked.connect ((b) => {
+ this.is_set = true;
+ changed ();
+ destroy ();
});
+ titlebar.pack_end (ok_button);
}
- public BirthdayEditor (Gtk.Window window, DateTime? birthday) {
- Object (transient_for: window, use_header_bar: 1, modal: true);
+ public BirthdayEditor (Gtk.Window? window, DateTime? birthday) {
+ Object (transient_for: window, modal: true);
// Don't forget to change to local timezone first
var bday_local = (birthday != null)? birthday.to_local () : new DateTime.now_local ();
diff --git a/src/contacts-crop-dialog.vala b/src/contacts-crop-dialog.vala
index 0a9cbb2..32876e7 100644
--- a/src/contacts-crop-dialog.vala
+++ b/src/contacts-crop-dialog.vala
@@ -16,28 +16,33 @@
*/
[GtkTemplate (ui = "/org/gnome/Contacts/ui/contacts-crop-dialog.ui")]
-public class Contacts.CropDialog : Gtk.Dialog {
-
- [GtkChild]
- private unowned Gtk.Box box;
+public class Contacts.CropDialog : Gtk.Window {
private Cc.CropArea crop_area;
+ public signal void cropped (Gdk.Pixbuf pixbuf);
+
+ static construct {
+ install_action ("crop", null, (Gtk.WidgetActionActivateFunc) on_crop);
+ }
+
construct {
this.crop_area = new Cc.CropArea ();
this.crop_area.vexpand = true;
this.crop_area.hexpand = true;
this.crop_area.set_min_size (48, 48);
- this.box.append (this.crop_area);
+ this.child = this.crop_area;
}
- public CropDialog.for_pixbuf (Gdk.Pixbuf pixbuf, Gtk.Window? parent = null) {
- Object (use_header_bar: 1, transient_for: parent);
+ public CropDialog.for_pixbuf (Gdk.Pixbuf pixbuf,
+ Gtk.Window? parent = null) {
+ Object (transient_for: parent);
this.crop_area.set_paintable (Gdk.Texture.for_pixbuf (pixbuf));
}
- public Gdk.Pixbuf create_pixbuf () {
- return this.crop_area.create_pixbuf ();
+ private void on_crop (string action_name, Variant? param) {
+ cropped (this.crop_area.create_pixbuf ());
+ destroy ();
}
}
diff --git a/src/contacts-linked-personas-dialog.vala b/src/contacts-linked-personas-dialog.vala
deleted file mode 100644
index f010554..0000000
--- a/src/contacts-linked-personas-dialog.vala
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2011 Alexander Larsson <alexl@redhat.com>
- *
- * 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 2 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 <http://www.gnu.org/licenses/>.
- */
-
-using Folks;
-
-[GtkTemplate (ui = "/org/gnome/Contacts/ui/contacts-linked-personas-dialog.ui")]
-public class Contacts.LinkedPersonasDialog : Gtk.Dialog {
- private const int AVATAR_SIZE = 54;
-
- [GtkChild]
- private unowned Gtk.ListBox linked_accounts_view;
-
- private Individual individual;
-
- public bool any_unlinked = false;
-
- public LinkedPersonasDialog (Gtk.Window main_win, Store store, Individual individual) {
- Object (
- use_header_bar: 1,
- transient_for: main_win,
- title: individual.display_name
- );
-
- this.individual = individual;
- this.linked_accounts_view.set_header_func (add_separator);
-
- // loading personas for display
- var personas = Utils.personas_as_list_model (individual);
- var personas_filtered = new Gtk.FilterListModel (personas, new PersonaFilter ());
- var personas_sorted = new Gtk.SortListModel (personas_filtered, new PersonaSorter ());
- this.linked_accounts_view.bind_model (personas_sorted, create_row_for_persona);
- }
-
- private Gtk.Widget create_row_for_persona (GLib.Object item) {
- unowned var persona = (Persona) item;
-
- var row_grid = new Gtk.Grid ();
-
- var image_frame = new Avatar (AVATAR_SIZE, individual);
- image_frame.set_hexpand (false);
- image_frame.margin_top = 6;
- image_frame.margin_bottom = 6;
- image_frame.margin_start = 6;
- image_frame.margin_end = 12;
- row_grid.attach (image_frame, 0, 0, 1, 2);
-
- var display_name = new Gtk.Label ("");
- display_name.set_halign (Gtk.Align.START);
- display_name.set_valign (Gtk.Align.END);
- display_name.set_hexpand (true);
- display_name.set_markup (Markup.printf_escaped ("<span font='bold'>%s</span>", persona.display_id));
-
- row_grid.attach (display_name, 1, 0, 1, 1);
-
- var store_name = new Gtk.Label (Contacts.Utils.format_persona_store_name_for_contact (persona));
- store_name.set_halign (Gtk.Align.START);
- store_name.set_valign (Gtk.Align.START);
- store_name.set_hexpand (true);
- store_name.get_style_context ().add_class ("dim-label");
- row_grid.attach (store_name, 1, 1, 1, 1);
-
- var button = new Gtk.Button.with_label (_("Unlink"));
- button.margin_end = 6;
- button.set_valign (Gtk.Align.CENTER);
- // button.get_child ().margin = 1; XXX
- row_grid.attach (button, 2, 0, 1, 2);
-
- /* signal */
- button.clicked.connect (() => {
- // TODO: handly unlinking
- });
-
- return row_grid;
- }
-
- private void add_separator (Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row) {
- row.set_header (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
- }
-}
diff --git a/src/meson.build b/src/meson.build
index 6f680e8..821f240 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -93,7 +93,6 @@ contacts_vala_sources = files(
'contacts-contact-sheet.vala',
'contacts-crop-dialog.vala',
'contacts-link-suggestion-grid.vala',
- 'contacts-linked-personas-dialog.vala',
'contacts-main-window.vala',
'contacts-qr-code-dialog.vala',
'contacts-preferences-window.vala',