105
105
int rebuild_flags;
106
106
GDBusConnection * conn;
107
107
GCancellable * cancellable;
109
/* serialized icon cache */
110
GVariant * alert_icon_serialized;
111
GVariant * default_icon_serialized;
114
110
typedef IndicatorSessionServicePrivate priv_t;
151
action_state_for_header (IndicatorSessionService * self)
147
update_header_action (IndicatorSessionService * self)
153
const priv_t * const p = self->priv;
154
150
gboolean need_attn;
155
GVariant * serialized_icon;
156
151
gboolean show_name;
157
153
const gchar * real_name;
158
154
const gchar * label;
155
const gchar * iconstr;
156
const priv_t * const p = self->priv;
158
g_return_if_fail (p->header_action != NULL);
163
160
if (indicator_session_actions_has_online_account_error (p->backend_actions))
165
162
need_attn = TRUE;
166
serialized_icon = p->alert_icon_serialized;
163
iconstr = ICON_ALERT;
170
167
need_attn = FALSE;
171
serialized_icon = p->default_icon_serialized;
168
iconstr = ICON_DEFAULT;
174
171
show_name = g_settings_get_boolean (p->indicator_settings,
197
194
a11y = g_strdup (_("System"));
200
/* build the state */
201
g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}"));
202
g_variant_builder_add (&b, "{sv}", "accessible-desc", g_variant_new_string (a11y));
203
if (serialized_icon != NULL)
204
g_variant_builder_add (&b, "{sv}", "icon", serialized_icon);
206
g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (label));
207
g_variant_builder_add (&b, "{sv}", "visible", g_variant_new_boolean (TRUE));
208
state = g_variant_builder_end (&b);
197
variant = g_variant_new ("(sssb)", label, iconstr, a11y, TRUE);
198
g_simple_action_set_state (p->header_action, variant);
217
update_header_action (IndicatorSessionService * self)
219
g_simple_action_set_state (self->priv->header_action, action_state_for_header (self));
276
256
static const char *
277
get_user_label (const IndicatorSessionUser * user)
281
/* If blank or whitespace, use username instead */
282
for (c = user->real_name; *c != '\0' && g_ascii_isspace (*c); c++);
284
return user->user_name;
286
return user->real_name;
290
257
get_current_real_name (IndicatorSessionService * self)
292
259
GHashTableIter iter;
448
415
const IndicatorSessionUser * a = *(const IndicatorSessionUser**)ga;
449
416
const IndicatorSessionUser * b = *(const IndicatorSessionUser**)gb;
451
if ((i = g_strcmp0 (get_user_label (a), get_user_label (b))))
418
if ((i = g_strcmp0 (a->real_name, b->real_name)))
454
421
return g_strcmp0 (a->user_name, b->user_name);
458
serialize_icon_file (const gchar * filename)
460
GVariant * serialized_icon = NULL;
462
if (filename != NULL)
464
GFile * file = g_file_new_for_path (filename);
465
GIcon * icon = g_file_icon_new (file);
467
serialized_icon = g_icon_serialize (icon);
469
g_object_unref (icon);
470
g_object_unref (file);
473
return serialized_icon;
476
424
static GMenuModel *
477
425
create_switch_section (IndicatorSessionService * self)
500
448
item = g_menu_item_new (ellipsis ? _("Switch Account…")
501
449
: _("Switch Account"), action);
451
else if (g_hash_table_size (p->users) == 1)
453
const char * action = "indicator.switch-to-greeter";
454
item = g_menu_item_new (_("Lock"), action);
505
const char * action = "indicator.switch-to-screensaver";
507
if (g_hash_table_size (p->users) == 1)
508
item = g_menu_item_new (_("Lock"), action);
510
item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
511
: _("Lock/Switch Account"), action);
458
const char * action = "indicator.switch-to-greeter";
459
item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
460
: _("Lock/Switch Account"), action);
513
462
str = g_settings_get_string (p->keybinding_settings, "screensaver");
514
463
g_menu_item_set_attribute (item, "accel", "s", str);
547
496
for (i=0; i<users->len; ++i)
549
498
const IndicatorSessionUser * u = g_ptr_array_index (users, i);
550
GVariant * serialized_icon;
552
item = g_menu_item_new (get_user_label (u), NULL);
499
item = g_menu_item_new (u->real_name, NULL);
553
500
g_menu_item_set_action_and_target (item, "indicator.switch-to-user", "s", u->user_name);
554
501
g_menu_item_set_attribute (item, "x-canonical-type", "s", "indicator.user-menu-item");
556
if ((serialized_icon = serialize_icon_file (u->icon_file)))
503
if (u->icon_file != NULL)
558
g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, serialized_icon);
559
g_variant_unref (serialized_icon);
505
GFile * file = g_file_new_for_path (u->icon_file);
506
GIcon * icon = g_file_icon_new (file);
507
g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, g_icon_serialize (icon));
508
g_clear_object (&icon);
509
g_clear_object (&file);
562
512
g_menu_append_item (menu, item);
579
529
menu = g_menu_new ();
581
if ((profile == PROFILE_DESKTOP) &&
582
(indicator_session_actions_can_logout (p->backend_actions)))
531
if (indicator_session_actions_can_logout (p->backend_actions) && !g_settings_get_boolean (s, "suppress-logout-menuitem"))
584
533
const char * label = ellipsis ? _("Log Out…") : _("Log Out");
585
534
g_menu_append (menu, label, "indicator.logout");
591
540
if (indicator_session_actions_can_hibernate (p->backend_actions))
592
541
g_menu_append (menu, _("Hibernate"), "indicator.hibernate");
594
if (indicator_session_actions_can_reboot (p->backend_actions))
543
/* NB: check 'ellipsis' here to skip this item if prompting is enabled
544
because this shows the same prompt as 'Shut Down' in Unity */
545
if (!ellipsis && !g_settings_get_boolean (s, "suppress-restart-menuitem"))
596
547
const char * label = ellipsis ? _("Restart…") : _("Restart");
597
548
g_menu_append (menu, label, "indicator.reboot");
624
575
sections[n++] = create_admin_section ();
625
576
sections[n++] = create_settings_section (self);
626
577
sections[n++] = create_switch_section (self);
627
sections[n++] = create_session_section (self, profile);
578
sections[n++] = create_session_section (self);
629
580
else if (profile == PROFILE_GREETER)
631
sections[n++] = create_session_section (self, profile);
582
sections[n++] = create_session_section (self);
634
585
/* add sections to the submenu */
676
on_online_accounts_activated (GSimpleAction * a G_GNUC_UNUSED,
677
GVariant * param G_GNUC_UNUSED,
680
indicator_session_actions_online_accounts (get_backend_actions(gself));
684
627
on_help_activated (GSimpleAction * a G_GNUC_UNUSED,
685
628
GVariant * param G_GNUC_UNUSED,
778
721
priv_t * p = self->priv;
780
723
GActionEntry entries[] = {
781
{ "about", on_about_activated },
782
{ "help", on_help_activated },
783
{ "hibernate", on_hibernate_activated },
784
{ "logout", on_logout_activated },
785
{ "online-accounts", on_online_accounts_activated },
786
{ "reboot", on_reboot_activated },
787
{ "settings", on_settings_activated },
788
{ "switch-to-screensaver", on_screensaver_activated },
789
{ "switch-to-greeter", on_greeter_activated },
790
{ "suspend", on_suspend_activated },
791
{ "power-off", on_power_off_activated }
724
{ "about", on_about_activated },
725
{ "help", on_help_activated },
726
{ "settings", on_settings_activated },
727
{ "logout", on_logout_activated },
728
{ "suspend", on_suspend_activated },
729
{ "hibernate", on_hibernate_activated },
730
{ "reboot", on_reboot_activated },
731
{ "power-off", on_power_off_activated },
732
{ "switch-to-screensaver", on_screensaver_activated },
733
{ "switch-to-greeter", on_greeter_activated }
794
736
p->actions = g_simple_action_group_new ();
802
744
v = create_guest_switcher_state (self);
803
745
a = g_simple_action_new_stateful ("switch-to-guest", NULL, v);
804
746
g_signal_connect (a, "activate", G_CALLBACK(on_guest_activated), self);
805
g_action_map_add_action (G_ACTION_MAP (p->actions), G_ACTION(a));
747
g_simple_action_group_insert (p->actions, G_ACTION(a));
806
748
p->guest_switcher_action = a;
808
750
/* add switch-to-user action... parameter is the uesrname */
809
751
v = create_user_switcher_state (self);
810
752
a = g_simple_action_new_stateful ("switch-to-user", G_VARIANT_TYPE_STRING, v);
811
753
g_signal_connect (a, "activate", G_CALLBACK(on_user_activated), self);
812
g_action_map_add_action (G_ACTION_MAP (p->actions), G_ACTION(a));
754
g_simple_action_group_insert (p->actions, G_ACTION(a));
813
755
p->user_switcher_action = a;
815
757
/* add the header action */
816
a = g_simple_action_new_stateful ("_header", NULL,
817
action_state_for_header (self));
818
g_action_map_add_action (G_ACTION_MAP (p->actions), G_ACTION(a));
758
v = g_variant_new ("(sssb)", "label", ICON_DEFAULT, "a11y", TRUE);
759
a = g_simple_action_new_stateful ("_header", NULL, v);
760
g_simple_action_group_insert (p->actions, G_ACTION(a));
819
761
p->header_action = a;
821
763
rebuild_now (self, SECTION_HEADER);
869
811
if (sections & SECTION_SESSION)
871
rebuild_section (desktop->submenu, 3, create_session_section(self, PROFILE_DESKTOP));
872
rebuild_section (greeter->submenu, 0, create_session_section(self, PROFILE_GREETER));
813
rebuild_section (desktop->submenu, 3, create_session_section(self));
814
rebuild_section (greeter->submenu, 0, create_session_section(self));
1031
972
&p->backend_users,
1032
973
&p->backend_guest);
1034
/* build the serialized icon cache */
1036
icon = g_themed_icon_new_with_default_fallbacks (ICON_ALERT);
1037
p->alert_icon_serialized = g_icon_serialize (icon);
1038
g_object_unref (icon);
1040
icon = g_themed_icon_new_with_default_fallbacks (ICON_DEFAULT);
1041
p->default_icon_serialized = g_icon_serialize (icon);
1042
g_object_unref (icon);
1044
975
/* init our key-to-User table */
1045
976
p->users = g_hash_table_new_full (g_direct_hash,
1088
1019
G_CALLBACK(rebuild_switch_section_soon), self);
1089
1020
g_signal_connect_swapped (gp, "changed::suppress-logout-restart-shutdown",
1090
1021
G_CALLBACK(rebuild_session_section_soon), self);
1022
g_signal_connect_swapped (gp, "changed::suppress-logout-menuitem",
1023
G_CALLBACK(rebuild_session_section_soon), self);
1024
g_signal_connect_swapped (gp, "changed::suppress-restart-menuitem",
1025
G_CALLBACK(rebuild_session_section_soon), self);
1091
1026
g_signal_connect_swapped (gp, "changed::suppress-shutdown-menuitem",
1092
1027
G_CALLBACK(rebuild_session_section_soon), self);
1093
1028
g_signal_connect_swapped (gp, "changed::show-real-name-on-panel",
1198
1133
g_clear_object (&p->guest_switcher_action);
1199
1134
g_clear_object (&p->conn);
1201
/* clear the serialized icon cache */
1202
g_clear_pointer (&p->alert_icon_serialized, g_variant_unref);
1203
g_clear_pointer (&p->default_icon_serialized, g_variant_unref);
1205
1136
G_OBJECT_CLASS (indicator_session_service_parent_class)->dispose (o);