diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2023-05-07 20:53:09 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2023-05-07 20:53:09 +0200 |
commit | 7004a8b66768d6d8f9b358fc6960dab9424514ad (patch) | |
tree | 1043bc53c1bb25d386d7ebd59bb9637aa50f204c /src | |
parent | 3c44cdf781d4fcb55b4e0c95043f172f218baaa7 (diff) | |
parent | bfb99d8737fd6c62fa24c6980a4d916008de17c4 (diff) | |
download | arctica-greeter-7004a8b66768d6d8f9b358fc6960dab9424514ad.tar.gz arctica-greeter-7004a8b66768d6d8f9b358fc6960dab9424514ad.tar.bz2 arctica-greeter-7004a8b66768d6d8f9b358fc6960dab9424514ad.zip |
Merge branch 'tari01-pr/dbus-server'
Attributes GH PR #46: https://github.com/ArcticaProject/arctica-greeter/pull/46
Diffstat (limited to 'src')
-rw-r--r-- | src/arctica-greeter.vala | 124 | ||||
-rw-r--r-- | src/dash-box.vala | 4 | ||||
-rw-r--r-- | src/greeter-list.vala | 6 | ||||
-rw-r--r-- | src/idle-monitor.vala | 7 | ||||
-rw-r--r-- | src/list-stack.vala | 7 | ||||
-rw-r--r-- | src/main-window.vala | 5 | ||||
-rw-r--r-- | src/menubar.vala | 26 | ||||
-rw-r--r-- | src/prompt-box.vala | 20 | ||||
-rw-r--r-- | src/remote-logon-service.vala | 9 | ||||
-rw-r--r-- | src/settings-daemon.vala | 42 | ||||
-rw-r--r-- | src/settings.vala | 2 | ||||
-rw-r--r-- | src/shutdown-dialog.vala | 32 | ||||
-rw-r--r-- | src/toggle-box.vala | 14 | ||||
-rw-r--r-- | src/user-list.vala | 242 |
14 files changed, 385 insertions, 155 deletions
diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 3ba2ff4..4a38248 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 <mike.gabriel@das-netzwerkteam.de> + * 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 <robert.ancell@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ public const int grid_size = 40; @@ -34,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; @@ -55,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 { @@ -127,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 */ @@ -590,7 +621,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) { @@ -648,20 +682,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; @@ -1221,7 +1257,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); @@ -1243,12 +1280,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 (); } @@ -1260,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); + } + } +} 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 <mike.gabriel@das-netzwerkteam.de> + * 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 <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ public class DashBox : Gtk.Box @@ -141,6 +143,8 @@ public class DashBox : Gtk.Box queue_resize (); orig.grab_focus (); break; + default: + return; } } 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 <mike.gabriel@das-netzwerkteam.de> + * 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 <michael.terry@canonical.com> * Scott Sweeny <scott.sweeny@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ 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/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 <mike.gabriel@das-netzwerkteam.de> + * Copyright (C) 2023 Robert Tari <robert@tari.in> * * 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 <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ public class ListStack : Gtk.Fixed @@ -75,7 +77,10 @@ public class ListStack : Gtk.Fixed unowned List<weak Gtk.Widget> 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/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 d9dab66..a53b461 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 <mike.gabriel@das-netzwerkteam.de> + * 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 <robert.ancell@canonical.com> * Michael Terry <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ 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); @@ -266,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 */ @@ -601,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) { @@ -644,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/prompt-box.vala b/src/prompt-box.vala index e1dc629..5716ab1 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 <mike.gabriel@das-netzwerkteam.de> + * 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 <robert.ancell@canonical.com> * Michael Terry <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ 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:]]*)(?<font_family>[ a-zA-Z0-9]+) (?<font_size>[0-9]+)([[:blank:]]*)$"); + Regex font_regexp = null; + + try + { + font_regexp = new Regex ("^([[:blank:]]*)(?<font_family>[ a-zA-Z0-9]+) (?<font_size>[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"); @@ -226,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); @@ -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 { @@ -328,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/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 <mike.gabriel@das-netzwerkteam.de> + * Copyright (C) 2023 Robert Tari <robert@tari.in> * * 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..be34e9c 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 <mike.gabriel@das-netzwerkteam.de> + * 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 <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ public class SettingsDaemon : Object @@ -223,16 +225,40 @@ 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); + } + }); + } } } - public void set_active (bool value) + public void set_active (bool value) throws GLib.DBusError, GLib.IOError { if (_active == value) return; @@ -246,15 +272,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")] 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 <mike.gabriel@das-netzwerkteam.de> * Copyright (C) 2022 Mihai Moldovan <ionic@ionic.de> + * 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 <robert.ancell@canonical.com> * Michael Terry <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ [SingleInstance] diff --git a/src/shutdown-dialog.vala b/src/shutdown-dialog.vala index d0820ee..9c5be6e 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 <mike.gabriel@das-netzwerkteam.de> + * 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 <robert.ancell@canonical.com> * Marco Trevisan <marco.trevisan@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ 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:]]*)(?<font_family>[ a-zA-Z0-9]+) (?<font_size>[0-9]+)([[:blank:]]*)$"); + Regex font_regexp = null; + + try + { + font_regexp = new Regex ("^([[:blank:]]*)(?<font_family>[ a-zA-Z0-9]+) (?<font_size>[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"); @@ -351,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 (); } @@ -616,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/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 <mike.gabriel@das-netzwerkteam.de> + * 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 <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ 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:]]*)(?<font_family>[ a-zA-Z0-9]+) (?<font_size>[0-9]+)([[:blank:]]*)$"); + Regex font_regexp = null; + + try + { + font_regexp = new Regex ("^([[:blank:]]*)(?<font_family>[ a-zA-Z0-9]+) (?<font_size>[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..e410b19 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 <mike.gabriel@das-netzwerkteam.de> + * 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 <robert.ancell@canonical.com> * Michael Terry <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ 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; @@ -620,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; @@ -668,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 (); @@ -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<RemoteServerField?> (); - 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<RemoteServerField?> (); + 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<string> (); - 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<string> (); + 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 () |