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(-) (limited to 'src') 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