X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fgnome-ask-password-agent.vala;h=e23aedbfee435e22b1db545a742e4cd091b82920;hp=1523e2e3bef16d805a6845d795085399a5c294c4;hb=5ebff5337594d690b322078c512eb222d34aaa82;hpb=afe635e71838c9e62e25a928cbcefc343744dda5 diff --git a/src/gnome-ask-password-agent.vala b/src/gnome-ask-password-agent.vala index 1523e2e3b..e23aedbfe 100644 --- a/src/gnome-ask-password-agent.vala +++ b/src/gnome-ask-password-agent.vala @@ -19,7 +19,6 @@ using Gtk; using GLib; -using DBus; using Linux; using Posix; using Notify; @@ -38,8 +37,8 @@ public class PasswordDialog : Dialog { set_default_response(ResponseType.OK); set_icon_name(icon); - add_button(STOCK_CANCEL, ResponseType.CANCEL); - add_button(STOCK_OK, ResponseType.OK); + add_button(Stock.CANCEL, ResponseType.CANCEL); + add_button(Stock.OK, ResponseType.OK); Container content = (Container) get_content_area(); @@ -85,9 +84,9 @@ public class MyStatusIcon : StatusIcon { public MyStatusIcon() throws GLib.Error { GLib.Object(icon_name : "dialog-password"); - set_title("System Password"); + set_title("System Password Request"); - directory = File.new_for_path("/dev/.systemd/ask-password/"); + directory = File.new_for_path("/run/systemd/ask-password/"); file_monitor = directory.monitor_directory(0); file_monitor.changed.connect(file_monitor_changed); @@ -97,14 +96,19 @@ public class MyStatusIcon : StatusIcon { activate.connect(status_icon_activate); } - void file_monitor_changed(GLib.File file, GLib.File? other_file, GLib.FileMonitorEvent event_type) throws GLib.Error { + void file_monitor_changed(GLib.File file, GLib.File? other_file, GLib.FileMonitorEvent event_type) { if (!file.get_basename().has_prefix("ask.")) return; if (event_type == FileMonitorEvent.CREATED || - event_type == FileMonitorEvent.DELETED) - look_for_password(); + event_type == FileMonitorEvent.DELETED) { + try { + look_for_password(); + } catch (Error e) { + show_error(e.message); + } + } } void look_for_password() throws GLib.Error { @@ -136,7 +140,6 @@ public class MyStatusIcon : StatusIcon { if (current == null) set_visible(false); - } bool load_password() throws GLib.Error { @@ -157,7 +160,7 @@ public class MyStatusIcon : StatusIcon { if (not_after_as_string.scanf("%llu", out not_after) != 1) return false; - if (not_after < now) + if (not_after > 0 && not_after < now) return false; socket = key_file.get_string("Ask", "Socket"); @@ -170,6 +173,7 @@ public class MyStatusIcon : StatusIcon { } catch (GLib.Error e) { message = "Please Enter System Password!"; } + set_tooltip_text(message); try { @@ -181,15 +185,14 @@ public class MyStatusIcon : StatusIcon { set_visible(true); - Notification n = new Notification(title, message, icon, null); - n.attach_to_status_icon(this); + Notification n = new Notification(title, message, icon); n.set_timeout(5000); n.show(); return true; } - void status_icon_activate() throws GLib.Error { + void status_icon_activate() { if (current == null) return; @@ -213,20 +216,27 @@ public class MyStatusIcon : StatusIcon { int to_process; - Process.spawn_async_with_pipes( - null, - { "/usr/bin/pkexec", "/lib/systemd/systemd-reply-password", result == ResponseType.OK ? "1" : "0", socket }, - null, - 0, - null, - null, - out to_process, - null, - null); - - OutputStream stream = new UnixOutputStream(to_process, true); - - stream.write(password, password.length, null); + try { + Process.spawn_async_with_pipes( + null, + { "/usr/bin/pkexec", "/lib/systemd/systemd-reply-password", result == ResponseType.OK ? "1" : "0", socket }, + null, + 0, + null, + null, + out to_process, + null, + null); + + OutputStream stream = new UnixOutputStream(to_process, true); +#if VALA_0_12 + stream.write(password.data, null); +#else + stream.write(password, password.length, null); +#endif + } catch (Error e) { + show_error(e.message); + } } } @@ -248,8 +258,6 @@ int main(string[] args) { MyStatusIcon i = new MyStatusIcon(); Gtk.main(); - } catch (DBus.Error e) { - show_error(e.message); } catch (GLib.Error e) { show_error(e.message); }