From 1c150a74abe1fa91d353903e5122ec6895bf23fd Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 5 May 2023 03:41:42 +0200 Subject: Fix error handlers for D-Bus methods --- src/arctica-greeter.vala | 6 ++++-- src/greeter-list.vala | 6 ++++-- src/remote-logon-service.vala | 9 +++++---- src/settings-daemon.vala | 14 ++++++++------ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 3ba2ff4..82d679e 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2011 Canonical Ltd * Copyright (C) 2015-2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -17,6 +18,7 @@ * * Authors: Robert Ancell * Mike Gabriel + * Robert Tari */ public const int grid_size = 40; @@ -1243,12 +1245,12 @@ public class DialogDBusInterface : Object public signal void open_dialog (uint32 type); public signal void close_dialog (); - public void open (uint32 type, uint32 timestamp, uint32 seconds_to_stay_open, ObjectPath[] inhibitor_object_paths) + public void open (uint32 type, uint32 timestamp, uint32 seconds_to_stay_open, ObjectPath[] inhibitor_object_paths) throws GLib.DBusError, GLib.IOError { open_dialog (type); } - public void close () + public void close () throws GLib.DBusError, GLib.IOError { close_dialog (); } diff --git a/src/greeter-list.vala b/src/greeter-list.vala index b1853cf..102c153 100644 --- a/src/greeter-list.vala +++ b/src/greeter-list.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2012 Canonical Ltd * Copyright (C) 2015-2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -19,6 +20,7 @@ * Michael Terry * Scott Sweeny * Mike Gabriel + * Robert Tari */ private const int MAX_FIELD_SIZE = 200; @@ -41,11 +43,11 @@ public class ListDBusInterface : Object }); } - public string get_active_entry () + public string get_active_entry () throws GLib.DBusError, GLib.IOError { return list.get_active_entry (); } - public void set_active_entry (string entry_name) + public void set_active_entry (string entry_name) throws GLib.DBusError, GLib.IOError { list.set_active_entry (entry_name); } diff --git a/src/remote-logon-service.vala b/src/remote-logon-service.vala index f0bfa7d..94bf5b9 100644 --- a/src/remote-logon-service.vala +++ b/src/remote-logon-service.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2012 Canonical Ltd * Copyright (C) 2015-2016 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -44,10 +45,10 @@ protected struct RemoteServer [DBus (name = "org.ArcticaProject.RemoteLogon")] interface RemoteLogonService : Object { - public abstract async void get_servers (out RemoteServer[] serverList) throws IOError; - public abstract async void get_servers_for_login (string url, string emailAddress, string password, bool allowCache, out bool loginSuccess, out string dataType, out RemoteServer[] serverList) throws IOError; - public abstract async void get_cached_domains_for_server (string url, out string[] domains) throws IOError; - public abstract async void set_last_used_server (string uccsUrl, string serverUrl) throws IOError; + public abstract async void get_servers (out RemoteServer[] serverList) throws GLib.DBusError, GLib.IOError; + public abstract async void get_servers_for_login (string url, string emailAddress, string password, bool allowCache, out bool loginSuccess, out string dataType, out RemoteServer[] serverList) throws GLib.DBusError, GLib.IOError; + public abstract async void get_cached_domains_for_server (string url, out string[] domains) throws GLib.DBusError, GLib.IOError; + public abstract async void set_last_used_server (string uccsUrl, string serverUrl) throws GLib.DBusError, GLib.IOError; public signal void servers_updated (RemoteServer[] serverList); public signal void login_servers_updated (string url, string emailAddress, string dataType, RemoteServer[] serverList); diff --git a/src/settings-daemon.vala b/src/settings-daemon.vala index 34dd99c..88bf698 100644 --- a/src/settings-daemon.vala +++ b/src/settings-daemon.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2011 Canonical Ltd * Copyright (C) 2015,2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -17,6 +18,7 @@ * * Authored by: Michael Terry * Mike Gabriel + * Robert Tari */ public class SettingsDaemon : Object @@ -232,7 +234,7 @@ public class ScreenSaverInterface : Object } } - public void set_active (bool value) + public void set_active (bool value) throws GLib.DBusError, GLib.IOError { if (_active == value) return; @@ -246,15 +248,15 @@ public class ScreenSaverInterface : Object active_changed (value); } - public bool get_active () + public bool get_active () throws GLib.DBusError, GLib.IOError { return _active; } - public uint32 get_active_time () { return 0; } - public void lock () {} - public void show_message (string summary, string body, string icon) {} - public void simulate_user_activity () {} + public uint32 get_active_time () throws GLib.DBusError, GLib.IOError { return 0; } + public void lock () throws GLib.DBusError, GLib.IOError {} + public void show_message (string summary, string body, string icon) throws GLib.DBusError, GLib.IOError {} + public void simulate_user_activity () throws GLib.DBusError, GLib.IOError {} } [DBus (name="org.gnome.SessionManager")] -- cgit v1.2.3 From c9b2de2b43d1575a85b5d0344c4a0bd1eb9f93fa Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 5 May 2023 04:31:30 +0200 Subject: Add missing error handlers --- src/menubar.vala | 13 ++- src/prompt-box.vala | 16 +++- src/settings-daemon.vala | 28 +++++- src/shutdown-dialog.vala | 14 ++- src/toggle-box.vala | 14 ++- src/user-list.vala | 238 ++++++++++++++++++++++++++--------------------- 6 files changed, 210 insertions(+), 113 deletions(-) diff --git a/src/menubar.vala b/src/menubar.vala index d9dab66..00fc862 100644 --- a/src/menubar.vala +++ b/src/menubar.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2011,2012 Canonical Ltd * Copyright (C) 2015-2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -18,6 +19,7 @@ * Authors: Robert Ancell * Michael Terry * Mike Gabriel + * Robert Tari */ private class IndicatorMenuItem : Gtk.MenuItem @@ -176,7 +178,16 @@ public class MenuBar : Gtk.MenuBar /* Add shadow. */ var shadow_style = new Gtk.CssProvider (); - shadow_style.load_from_data ("* { box-shadow: 0px 0px 5px 5px #000000; }", -1); + + try + { + shadow_style.load_from_data ("* { box-shadow: 0px 0px 5px 5px #000000; }", -1); + } + catch (Error pError) + { + error ("Panic: Failed adding shadow: %s", pError.message); + } + this.get_style_context ().add_provider (shadow_style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); diff --git a/src/prompt-box.vala b/src/prompt-box.vala index e1dc629..f429bc6 100644 --- a/src/prompt-box.vala +++ b/src/prompt-box.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2011,2012 Canonical Ltd * Copyright (C) 2015,2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -18,6 +19,7 @@ * Authors: Robert Ancell * Michael Terry * Mike Gabriel + * Robert Tari */ public class PromptBox : FadableBox @@ -176,7 +178,17 @@ public class PromptBox : FadableBox fixed.add (box_grid); /* Split font family and size via regular expression. */ - Regex font_regexp = new Regex ("^([[:blank:]]*)(?[ a-zA-Z0-9]+) (?[0-9]+)([[:blank:]]*)$"); + Regex font_regexp = null; + + try + { + font_regexp = new Regex ("^([[:blank:]]*)(?[ a-zA-Z0-9]+) (?[0-9]+)([[:blank:]]*)$"); + } + catch (GLib.RegexError pError) + { + error ("Panic: Failed constructing RegEx: %s", pError.message); + } + MatchInfo font_info; if (font_regexp.match(font, 0, out font_info)) { font_family = font_info.fetch_named("font_family"); @@ -310,7 +322,7 @@ public class PromptBox : FadableBox small_name_label = new FadingLabel (""); - var style_ctx = small_name_label.get_style_context(); + var style_ctx = small_name_label.get_style_context(); try { diff --git a/src/settings-daemon.vala b/src/settings-daemon.vala index 88bf698..be34e9c 100644 --- a/src/settings-daemon.vala +++ b/src/settings-daemon.vala @@ -225,12 +225,36 @@ public class ScreenSaverInterface : Object idle_monitor.remove_watch (idle_watch); idle_watch = 0; if (value) - idle_monitor.add_user_active_watch (() => set_active (false)); + { + idle_monitor.add_user_active_watch (() => + { + try + { + set_active (false); + } + catch (Error pError) + { + error ("Panic: Screensaver activation failed: %s", pError.message); + } + }); + } else { var timeout = AGSettings.get_integer (AGSettings.KEY_IDLE_TIMEOUT); if (timeout > 0) - idle_watch = idle_monitor.add_idle_watch (timeout * 1000, () => set_active (true)); + { + idle_watch = idle_monitor.add_idle_watch (timeout * 1000, () => + { + try + { + set_active (true); + } + catch (Error pError) + { + error ("Panic: Screensaver activation failed: %s", pError.message); + } + }); + } } } diff --git a/src/shutdown-dialog.vala b/src/shutdown-dialog.vala index d0820ee..c30ea0e 100644 --- a/src/shutdown-dialog.vala +++ b/src/shutdown-dialog.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2013 Canonical Ltd * Copyright (C) 2015,2016 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -18,6 +19,7 @@ * Authors: Robert Ancell * Marco Trevisan * Mike Gabriel + * Robert Tari */ public enum ShutdownDialogType @@ -100,7 +102,17 @@ public class ShutdownDialog : Gtk.Fixed monitor_events.add (vbox_events); /* Split font family and size via regular expression. */ - Regex font_regexp = new Regex ("^([[:blank:]]*)(?[ a-zA-Z0-9]+) (?[0-9]+)([[:blank:]]*)$"); + Regex font_regexp = null; + + try + { + font_regexp = new Regex ("^([[:blank:]]*)(?[ a-zA-Z0-9]+) (?[0-9]+)([[:blank:]]*)$"); + } + catch (GLib.RegexError pError) + { + error ("Panic: Failed constructing RegEx: %s", pError.message); + } + MatchInfo font_info; if (font_regexp.match(font, 0, out font_info)) { font_family = font_info.fetch_named("font_family"); diff --git a/src/toggle-box.vala b/src/toggle-box.vala index 0c6bf57..12072b1 100644 --- a/src/toggle-box.vala +++ b/src/toggle-box.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2012 Canonical Ltd * Copyright (C) 2015,2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -17,6 +18,7 @@ * * Authors: Michael Terry * Mike Gabriel + * Robert Tari */ public class ToggleBox : Gtk.Box @@ -72,7 +74,17 @@ public class ToggleBox : Gtk.Box } /* Split font family and size via regular expression. */ - Regex font_regexp = new Regex ("^([[:blank:]]*)(?[ a-zA-Z0-9]+) (?[0-9]+)([[:blank:]]*)$"); + Regex font_regexp = null; + + try + { + font_regexp = new Regex ("^([[:blank:]]*)(?[ a-zA-Z0-9]+) (?[0-9]+)([[:blank:]]*)$"); + } + catch (GLib.RegexError pError) + { + error ("Panic: Failed constructing RegEx: %s", pError.message); + } + MatchInfo font_info; if (font_regexp.match(font, 0, out font_info)) { font_family = font_info.fetch_named("font_family"); diff --git a/src/user-list.vala b/src/user-list.vala index 39ed7ae..9affbb9 100644 --- a/src/user-list.vala +++ b/src/user-list.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2011,2012 Canonical Ltd * Copyright (C) 2015-2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -18,6 +19,7 @@ * Authors: Robert Ancell * Michael Terry * Mike Gabriel + * Robert Tari */ int remote_server_field_sort_function (RemoteServerField? item1, RemoteServerField? item2) @@ -223,7 +225,16 @@ public class UserList : GreeterList try { RemoteServer[] server_list; - yield remote_logon_service.get_servers (out server_list); + + try + { + yield remote_logon_service.get_servers (out server_list); + } + catch (GLib.DBusError pError) + { + error ("Panic: Failed getting logon servers: %s", pError.message); + } + set_remote_directory_servers (server_list); } catch (IOError e) @@ -511,7 +522,15 @@ public class UserList : GreeterList // If we had an error and are retrying the same user and server, do not use the cache on R-L-S if (selected_entry.has_errors && currently_browsing_server_email == email && currently_browsing_server_url == url) allowcache = false; - yield remote_logon_service.get_servers_for_login (url, email, password_field.text, allowcache, out login_success, out data_type, out server_list); + + try + { + yield remote_logon_service.get_servers_for_login (url, email, password_field.text, allowcache, out login_success, out data_type, out server_list); + } + catch (GLib.DBusError pError) + { + error ("Panic: Failed getting login servers: %s", pError.message); + } } currently_browsing_server_url = url; currently_browsing_server_email = email; @@ -703,141 +722,148 @@ public class UserList : GreeterList var url = url_from_remote_loding_server_list_name (selected_entry.id); var username = username_from_remote_loding_server_list_name (selected_entry.id); - foreach (var remote_server in server_list) + try { - var remote_username = username_from_remote_server_fields (remote_server); - if (remote_server.url == url && (username == null || username == remote_username)) + foreach (var remote_server in server_list) { - if (selected_entry.id.has_prefix ("*remote_login")) + var remote_username = username_from_remote_server_fields (remote_server); + if (remote_server.url == url && (username == null || username == remote_username)) { - if (!is_supported_remote_session (remote_server.type)) + if (selected_entry.id.has_prefix ("*remote_login")) { - show_message (_("Server type not supported."), true); + if (!is_supported_remote_session (remote_server.type)) + { + show_message (_("Server type not supported."), true); + } } - } - var fields = new List (); - foreach (var field in remote_server.fields) - fields.append (field); - fields.sort (remote_server_field_sort_function); - foreach (var field in fields) - { - Gtk.Widget? widget = null; - var default_value = ""; - if (field.default_value != null && field.default_value.is_of_type (VariantType.STRING)) - default_value = field.default_value.get_string (); - if (field.type == "username") - { - var entry = add_prompt (_("Username:")); - entry.text = default_value; - widget = entry; - } - else if (field.type == "password") - { - var entry = add_prompt (_("Password:"), true); - entry.text = default_value; - widget = entry; - } - else if (field.type == "command") + var fields = new List (); + foreach (var field in remote_server.fields) + fields.append (field); + fields.sort (remote_server_field_sort_function); + foreach (var field in fields) { - var prompt = add_prompt (_("X2Go Session:")); - prompt.text = default_value; - prompt.sensitive = true; - widget = prompt; - } - else if (field.type == "domain") - { - string[] domainsArray = {}; - if (field.properties != null && field.properties.contains ("domains") && field.properties.get ("domains").is_of_type (VariantType.ARRAY)) - domainsArray = field.properties.get ("domains").dup_strv (); - var domains = new GenericArray (); - for (var i = 0; i < domainsArray.length; i++) - domains.add (domainsArray[i]); - - var read_only = field.properties != null && - field.properties.contains ("read-only") && - field.properties.get ("read-only").is_of_type (VariantType.BOOLEAN) && - field.properties.get ("read-only").get_boolean (); - if (domains.length == 0 || (domains.length == 1 && (domains[0] == default_value || default_value.length == 0))) + Gtk.Widget? widget = null; + var default_value = ""; + if (field.default_value != null && field.default_value.is_of_type (VariantType.STRING)) + default_value = field.default_value.get_string (); + if (field.type == "username") + { + var entry = add_prompt (_("Username:")); + entry.text = default_value; + widget = entry; + } + else if (field.type == "password") { - var prompt = add_prompt (_("Domain:")); - prompt.text = domains.length == 1 ? domains[0] : default_value; - prompt.sensitive = !read_only; + var entry = add_prompt (_("Password:"), true); + entry.text = default_value; + widget = entry; + } + else if (field.type == "command") + { + var prompt = add_prompt (_("X2Go Session:")); + prompt.text = default_value; + prompt.sensitive = true; widget = prompt; } - else + else if (field.type == "domain") { - if (default_value.length > 0) + string[] domainsArray = {}; + if (field.properties != null && field.properties.contains ("domains") && field.properties.get ("domains").is_of_type (VariantType.ARRAY)) + domainsArray = field.properties.get ("domains").dup_strv (); + var domains = new GenericArray (); + for (var i = 0; i < domainsArray.length; i++) + domains.add (domainsArray[i]); + + var read_only = field.properties != null && + field.properties.contains ("read-only") && + field.properties.get ("read-only").is_of_type (VariantType.BOOLEAN) && + field.properties.get ("read-only").get_boolean (); + if (domains.length == 0 || (domains.length == 1 && (domains[0] == default_value || default_value.length == 0))) { - /* Make sure the domain list contains the default value */ - var found = false; - for (var i = 0; !found && i < domains.length; i++) - found = default_value == domains[i]; - - if (!found) - domains.add (default_value); + var prompt = add_prompt (_("Domain:")); + prompt.text = domains.length == 1 ? domains[0] : default_value; + prompt.sensitive = !read_only; + widget = prompt; } + else + { + if (default_value.length > 0) + { + /* Make sure the domain list contains the default value */ + var found = false; + for (var i = 0; !found && i < domains.length; i++) + found = default_value == domains[i]; - /* Sort domains alphabetically */ - domains.sort (strcmp); - var combo = add_combo (domains, read_only); + if (!found) + domains.add (default_value); + } - if (default_value.length > 0) - { - if (read_only) + /* Sort domains alphabetically */ + domains.sort (strcmp); + var combo = add_combo (domains, read_only); + + if (default_value.length > 0) { - for (var i = 0; i < domains.length; i++) + if (read_only) { - if (default_value == domains[i]) + for (var i = 0; i < domains.length; i++) { - combo.active = i; - break; + if (default_value == domains[i]) + { + combo.active = i; + break; + } } } + else + { + var entry = combo.get_child () as Gtk.Entry; + entry.text = default_value; + } } - else - { - var entry = combo.get_child () as Gtk.Entry; - entry.text = default_value; - } - } - widget = combo; + widget = combo; + } } - } - else if (field.type == "email") - { - string[] email_domains; - var greeter = new ArcticaGreeter (); - try + else if (field.type == "email") { - if (greeter.test_mode) - email_domains = { "canonical.com", "ubuntu.org", "candy.com", "urban.net" }; - else - yield remote_logon_service.get_cached_domains_for_server (url, out email_domains); + string[] email_domains; + var greeter = new ArcticaGreeter (); + try + { + if (greeter.test_mode) + email_domains = { "canonical.com", "ubuntu.org", "candy.com", "urban.net" }; + else + yield remote_logon_service.get_cached_domains_for_server (url, out email_domains); + } + catch (IOError e) + { + email_domains.resize (0); + debug ("Calling get_cached_domains_for_server in org.ArcticaProject.RemoteLogon dbus service failed. Error: %s", e.message); + } + + var entry = add_prompt (_("Account ID")); + entry.text = default_value; + widget = entry; + if (email_domains.length > 0) + remote_server_email_field_autocompleter = new EmailAutocompleter (entry, email_domains); } - catch (IOError e) + else { - email_domains.resize (0); - debug ("Calling get_cached_domains_for_server in org.ArcticaProject.RemoteLogon dbus service failed. Error: %s", e.message); + debug ("Found field of type %s, don't know what to do with it", field.type); + continue; } - - var entry = add_prompt (_("Account ID")); - entry.text = default_value; - widget = entry; - if (email_domains.length > 0) - remote_server_email_field_autocompleter = new EmailAutocompleter (entry, email_domains); - } - else - { - debug ("Found field of type %s, don't know what to do with it", field.type); - continue; + current_remote_fields.insert (field.type, widget); } - current_remote_fields.insert (field.type, widget); + break; } - break; } } + catch (GLib.DBusError pError) + { + error ("Panic: Failed iterating through remote servers: %s", pError.message); + } } public override void focus_prompt () -- cgit v1.2.3 From 0718f264357a13b1a55cadcb7eb6a5774b7dd7eb Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 5 May 2023 05:19:44 +0200 Subject: Fix casting issues --- src/arctica-greeter.vala | 20 +++++++++++++------- src/idle-monitor.vala | 7 ++++++- src/list-stack.vala | 7 ++++++- src/menubar.vala | 7 +++++-- src/shutdown-dialog.vala | 18 +++++++++++++----- src/user-list.vala | 4 ++-- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 82d679e..9911f87 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -592,7 +592,10 @@ public class ArcticaGreeter : Object /* Check to see if this window is our onboard window, since we don't want to focus it. */ X.Window keyboard_xid = 0; if (main_window.menubar.keyboard_window != null) - keyboard_xid = (main_window.menubar.keyboard_window.get_window () as Gdk.X11.Window).get_xid (); + { + Gdk.X11.Window pWindow = (Gdk.X11.Window) main_window.menubar.keyboard_window.get_window (); + keyboard_xid = pWindow.get_xid (); + } if (xwin != keyboard_xid && win.get_type_hint() != Gdk.WindowTypeHint.NOTIFICATION) { @@ -650,20 +653,22 @@ public class ArcticaGreeter : Object private static Cairo.XlibSurface? create_root_surface (Gdk.Screen screen) { var visual = screen.get_system_visual (); - - unowned X.Display display = (screen.get_display () as Gdk.X11.Display).get_xdisplay (); - unowned X.Screen xscreen = (screen as Gdk.X11.Screen).get_xscreen (); + Gdk.X11.Display pDisplay = (Gdk.X11.Display) screen.get_display (); + unowned X.Display display = pDisplay.get_xdisplay (); + Gdk.X11.Screen pScreen = (Gdk.X11.Screen) screen; + unowned X.Screen xscreen = pScreen.get_xscreen (); var pixmap = X.CreatePixmap (display, - (screen.get_root_window () as Gdk.X11.Window).get_xid (), + ((Gdk.X11.Window) (screen.get_root_window ())).get_xid (), xscreen.width_of_screen (), xscreen.height_of_screen (), visual.get_depth ()); /* Convert into a Cairo surface */ + Gdk.X11.Visual pVisual = (Gdk.X11.Visual) visual; var surface = new Cairo.XlibSurface (display, pixmap, - (visual as Gdk.X11.Visual).get_xvisual (), + pVisual.get_xvisual (), xscreen.width_of_screen (), xscreen.height_of_screen ()); return surface; @@ -1223,7 +1228,8 @@ public class ArcticaGreeter : Object } var screen = Gdk.Screen.get_default (); - unowned X.Display xdisplay = (screen.get_display () as Gdk.X11.Display).get_xdisplay (); + Gdk.X11.Display pDisplay = (Gdk.X11.Display) screen.get_display (); + unowned X.Display xdisplay = pDisplay.get_xdisplay (); var window = xdisplay.default_root_window(); var atom = xdisplay.intern_atom ("AT_SPI_BUS", true); diff --git a/src/idle-monitor.vala b/src/idle-monitor.vala index 374e924..b8e8963 100644 --- a/src/idle-monitor.vala +++ b/src/idle-monitor.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2014 Canonical Ltd * Copyright (C) 2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -79,7 +80,11 @@ public class IdleMonitor warning ("Only support idle monitor under X"); return; } - display = (d as Gdk.X11.Display).get_xdisplay (); + + if (d is Gdk.X11.Display) + { + display = d.get_xdisplay (); + } int sync_error_base; var res = X.Sync.QueryExtension (display, out sync_event_base, out sync_error_base); diff --git a/src/list-stack.vala b/src/list-stack.vala index 8f6e371..63bde28 100644 --- a/src/list-stack.vala +++ b/src/list-stack.vala @@ -1,6 +1,7 @@ /* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*- * * Copyright (C) 2011,2012 Canonical Ltd + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -16,6 +17,7 @@ * * Authors: Michael Terry * Mike Gabriel + * Robert Tari */ public class ListStack : Gtk.Fixed @@ -75,7 +77,10 @@ public class ListStack : Gtk.Fixed unowned List prev = children.last ().prev; if (prev != null) - (prev.data as GreeterList).greeter_box.pop (); + { + GreeterList pList = (GreeterList) prev.data; + pList.greeter_box.pop (); + } } public override void size_allocate (Gtk.Allocation allocation) diff --git a/src/menubar.vala b/src/menubar.vala index 00fc862..5e8b2ef 100644 --- a/src/menubar.vala +++ b/src/menubar.vala @@ -655,8 +655,11 @@ public class MenuBar : Gtk.MenuBar // why we do both. Ideally this would be fixed in orca itself. var greeter = new ArcticaGreeter (); greeter.orca_needs_kick = true; - Timeout.add_seconds (1, () => { - Signal.emit_by_name ((get_toplevel () as Gtk.Window).get_focus ().get_accessible (), "focus-event", true); + Timeout.add_seconds (1, () => + { + Gtk.Window pWindow = (Gtk.Window) get_toplevel (); + Signal.emit_by_name (pWindow.get_focus ().get_accessible (), "focus-event", true); + return false; }); } diff --git a/src/shutdown-dialog.vala b/src/shutdown-dialog.vala index c30ea0e..9c5be6e 100644 --- a/src/shutdown-dialog.vala +++ b/src/shutdown-dialog.vala @@ -363,19 +363,26 @@ public class ShutdownDialog : Gtk.Fixed public void focus_next () { - (get_toplevel () as Gtk.Window).move_focus (Gtk.DirectionType.TAB_FORWARD); + Gtk.Window pWindow = (Gtk.Window) get_toplevel (); + pWindow.move_focus (Gtk.DirectionType.TAB_FORWARD); } public void focus_prev () { - (get_toplevel () as Gtk.Window).move_focus (Gtk.DirectionType.TAB_BACKWARD); + Gtk.Window pWindow = (Gtk.Window) get_toplevel (); + pWindow.move_focus (Gtk.DirectionType.TAB_BACKWARD); } public void cancel () { - var widget = (get_toplevel () as Gtk.Window).get_focus (); + Gtk.Window pWindow = (Gtk.Window) get_toplevel (); + var widget = pWindow.get_focus (); + if (widget is DialogButton) - (get_toplevel () as Gtk.Window).set_focus (null); + { + pWindow = (Gtk.Window) get_toplevel (); + pWindow.set_focus (null); + } else close (); } @@ -628,7 +635,8 @@ private class DialogButton : Gtk.Button public override bool leave_notify_event (Gdk.EventCrossing event) { - (get_toplevel () as Gtk.Window).set_focus (null); + Gtk.Window pWindow = (Gtk.Window) get_toplevel (); + pWindow.set_focus (null); return base.leave_notify_event (event); } diff --git a/src/user-list.vala b/src/user-list.vala index 9affbb9..e410b19 100644 --- a/src/user-list.vala +++ b/src/user-list.vala @@ -639,7 +639,7 @@ public class UserList : GreeterList if (agsettings.high_contrast || !AGSettings.get_boolean (AGSettings.KEY_DRAW_USER_BACKGROUNDS)) new_background_file = null; else if (selected_entry is UserPromptBox) - new_background_file = (selected_entry as UserPromptBox).background; + new_background_file = ((UserPromptBox) selected_entry).background; background.current_background = new_background_file; @@ -687,7 +687,7 @@ public class UserList : GreeterList var greeter = new ArcticaGreeter (); greeter.set_state ("last-user", username); if (selected_entry is UserPromptBox) - session = (selected_entry as UserPromptBox).session; + session = ((UserPromptBox) selected_entry).session; else session = null; selected_entry.clear (); -- cgit v1.2.3 From a2240b30a817a367c85c9de6063acf1222a0fac3 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Sat, 6 May 2023 01:50:27 +0200 Subject: Comment out unused code --- src/menubar.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/menubar.vala b/src/menubar.vala index 5e8b2ef..4438b04 100644 --- a/src/menubar.vala +++ b/src/menubar.vala @@ -612,11 +612,11 @@ public class MenuBar : Gtk.MenuBar agsettings.high_contrast = item.active; } - private void big_font_toggled_cb (Gtk.CheckMenuItem item) + /*private void big_font_toggled_cb (Gtk.CheckMenuItem item) { var agsettings = new AGSettings (); agsettings.big_font = item.active; - } + }*/ private void screen_reader_toggled_cb (Gtk.CheckMenuItem item) { -- cgit v1.2.3 From a919238f30e02cc996eb842d0ab4a0922964d77e Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Sat, 6 May 2023 02:45:49 +0200 Subject: Fix some deprecations --- src/main-window.vala | 5 ++--- src/menubar.vala | 2 +- src/prompt-box.vala | 4 ++-- src/settings.vala | 2 ++ 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main-window.vala b/src/main-window.vala index fd1e19c..32df287 100644 --- a/src/main-window.vala +++ b/src/main-window.vala @@ -52,7 +52,6 @@ public class MainWindow : Gtk.Window bg_color.parse (AGSettings.get_string (AGSettings.KEY_BACKGROUND_COLOR)); override_background_color (Gtk.StateFlags.NORMAL, bg_color); get_accessible ().set_name (_("Login Screen")); - has_resize_grip = false; ArcticaGreeter.add_style_class (this); background = new Background (); @@ -201,8 +200,8 @@ public class MainWindow : Gtk.Window if (hbox != null) { - hbox.margin_left = get_grid_offset (get_allocated_width ()) + grid_size; - hbox.margin_right = get_grid_offset (get_allocated_width ()); + hbox.margin_start = get_grid_offset (get_allocated_width ()) + grid_size; + hbox.margin_end = get_grid_offset (get_allocated_width ()); hbox.margin_top = get_grid_offset (get_allocated_height ()); hbox.margin_bottom = get_grid_offset (get_allocated_height ()); } diff --git a/src/menubar.vala b/src/menubar.vala index 4438b04..a53b461 100644 --- a/src/menubar.vala +++ b/src/menubar.vala @@ -277,7 +277,7 @@ public class MenuBar : Gtk.MenuBar hostname_item.set_sensitive (false); - hostname_item.set_right_justified (true); + hostname_item.set_halign (Gtk.Align.END); } /* Prevent dragging the window by the menubar */ diff --git a/src/prompt-box.vala b/src/prompt-box.vala index f429bc6..5716ab1 100644 --- a/src/prompt-box.vala +++ b/src/prompt-box.vala @@ -238,7 +238,7 @@ public class PromptBox : FadableBox name_label.vexpand = true; name_label.yalign = 0.5f; name_label.xalign = 0.0f; - name_label.margin_left = 2; + name_label.margin_start = 2; name_label.set_size_request (-1, grid_size); name_label.show (); name_grid.attach (name_label, COL_NAME_LABEL, ROW_NAME, 1, 1); @@ -340,7 +340,7 @@ public class PromptBox : FadableBox small_name_label.override_color (Gtk.StateFlags.NORMAL, { 1.0f, 1.0f, 1.0f, 1.0f }); small_name_label.yalign = 0.5f; small_name_label.xalign = 0.0f; - small_name_label.margin_left = 2; + small_name_label.margin_start = 2; small_name_label.set_size_request (-1, grid_size); small_name_label.show (); small_name_grid.attach (small_name_label, 1, 0, 1, 1); diff --git a/src/settings.vala b/src/settings.vala index 33d40c1..30f25ed 100644 --- a/src/settings.vala +++ b/src/settings.vala @@ -3,6 +3,7 @@ * Copyright (C) 2011,2012 Canonical Ltd * Copyright (C) 2015,2017 Mike Gabriel * Copyright (C) 2022 Mihai Moldovan + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -19,6 +20,7 @@ * Authors: Robert Ancell * Michael Terry * Mike Gabriel + * Robert Tari */ [SingleInstance] -- cgit v1.2.3 From 36ac6b17fe6e4087c49b636123071bdfc1533f5a Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Sat, 6 May 2023 02:53:23 +0200 Subject: Add missing default to switch --- src/dash-box.vala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dash-box.vala b/src/dash-box.vala index 1073aa5..4d907db 100644 --- a/src/dash-box.vala +++ b/src/dash-box.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2011,2012 Canonical Ltd * Copyright (C) 2015 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -17,6 +18,7 @@ * * Authors: Michael Terry * Mike Gabriel + * Robert Tari */ public class DashBox : Gtk.Box @@ -141,6 +143,8 @@ public class DashBox : Gtk.Box queue_resize (); orig.grab_focus (); break; + default: + return; } } -- cgit v1.2.3 From bfb99d8737fd6c62fa24c6980a4d916008de17c4 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Sat, 6 May 2023 03:09:41 +0200 Subject: src/arctica-greeter.vala: Add D-Bus server with methods needed by the keyboard indicator --- src/arctica-greeter.vala | 98 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 9911f87..4a38248 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -36,7 +36,7 @@ public class ArcticaGreeter : Object public bool test_bigfont { get; construct; default = false; } private string state_file; private KeyFile state; - + private DBusServer pServer; private Cairo.XlibSurface background_surface; private SettingsDaemon settings_daemon; @@ -57,9 +57,25 @@ public class ArcticaGreeter : Object construct { + Bus.own_name (BusType.SESSION, "org.ArcticaProject.ArcticaGreeter", BusNameOwnerFlags.NONE, onBusAcquired); + greeter = new LightDM.Greeter (); greeter.show_message.connect ((text, type) => { show_message (text, type); }); - greeter.show_prompt.connect ((text, type) => { show_prompt (text, type); }); + + greeter.show_prompt.connect ((text, type) => + { + try + { + this.pServer.sendUserChange (); + } + catch (Error pError) + { + error ("Panic: %s", pError.message); + } + + show_prompt (text, type); + }); + greeter.autologin_timer_expired.connect (() => { try { @@ -129,6 +145,19 @@ public class ArcticaGreeter : Object ); } + private void onBusAcquired (DBusConnection pConnection) + { + try + { + this.pServer = new DBusServer (pConnection, this.greeter); + pConnection.register_object ("/org/ArcticaProject/ArcticaGreeter", this.pServer); + } + catch (IOError pError) + { + error ("%s\n", pError.message); + } + } + public void go () { /* Render things after xsettings is ready */ @@ -1268,3 +1297,68 @@ private interface SettingsDaemonDBusInterface : Object public signal void plugin_activated (string name); public signal void plugin_deactivated (string name); } + +[DBus (name = "org.ArcticaProject.ArcticaGreeter")] +public class DBusServer : Object +{ + private DBusConnection pConnection; + private LightDM.Greeter pGreeter; + + public DBusServer (DBusConnection pConnection, LightDM.Greeter pGreeter) + { + this.pConnection = pConnection; + this.pGreeter = pGreeter; + } + + public void sendUserChange () throws GLib.DBusError, GLib.IOError + { + string sUser = this.pGreeter.get_authentication_user (); + + if (sUser == null) + { + sUser = "GUEST"; + } + + Variant pUser = new Variant ("(s)", sUser); + + try + { + this.pConnection.emit_signal (null, "/org/ArcticaProject/ArcticaGreeter", "org.ArcticaProject.ArcticaGreeter", "UserChanged", pUser); + } + catch (Error pError) + { + error ("Panic: Could not send user change signal: %s", pError.message); + } + } + + public string GetUser () throws GLib.DBusError, GLib.IOError + { + string sUser = this.pGreeter.get_authentication_user (); + + if (sUser == null) + { + sUser = "GUEST"; + } + + return sUser; + } + + public void SetLayout (string sLanguage, string sVariant) throws GLib.DBusError, GLib.IOError + { + string sCommand = "setxkbmap -layout %s".printf (sLanguage); + + if (sVariant != "") + { + sCommand = "%s -variant %s".printf (sCommand, sVariant); + } + + try + { + Process.spawn_command_line_sync (sCommand, null, null, null); + } + catch (Error pError) + { + error ("Panic: Could not set keyboard layout: %s", pError.message); + } + } +} -- cgit v1.2.3