~unity8-desktop-session-team/indicator-session/indicator-session-using-upstart

« back to all changes in this revision

Viewing changes to src/service.c

  • Committer: Ted Gould
  • Date: 2013-08-27 20:09:48 UTC
  • mto: This revision was merged to the branch mainline in revision 418.
  • Revision ID: ted@gould.cx-20130827200948-f57l9e2rcekcy92r
Dropping debugging for system-wide support

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
  SECTION_ADMIN     = (1<<1),
59
59
  SECTION_SETTINGS  = (1<<2),
60
60
  SECTION_SWITCH    = (1<<3),
61
 
  SECTION_LOGOUT    = (1<<4),
62
 
  SECTION_SESSION   = (1<<5)
 
61
  SECTION_SESSION   = (1<<4)
63
62
};
64
63
 
65
64
enum
106
105
  int rebuild_flags;
107
106
  GDBusConnection * conn;
108
107
  GCancellable * cancellable;
109
 
 
110
 
  /* serialized icon cache */
111
 
  GVariant * alert_icon_serialized;
112
 
  GVariant * default_icon_serialized;
113
108
};
114
109
 
115
110
typedef IndicatorSessionServicePrivate priv_t;
134
129
  rebuild_soon (self, SECTION_SWITCH);
135
130
}
136
131
static inline void
137
 
rebuild_logout_section_soon (IndicatorSessionService * self)
138
 
{
139
 
  rebuild_soon (self, SECTION_LOGOUT);
140
 
}
141
 
static inline void
142
132
rebuild_session_section_soon (IndicatorSessionService * self)
143
133
{
144
134
  rebuild_soon (self, SECTION_SESSION);
158
148
{
159
149
  const priv_t * const p = self->priv;
160
150
  gboolean need_attn;
161
 
  GVariant * serialized_icon;
 
151
  GIcon * icon;
162
152
  gboolean show_name;
163
153
  const gchar * real_name;
164
154
  const gchar * label;
169
159
  if (indicator_session_actions_has_online_account_error (p->backend_actions))
170
160
    {
171
161
      need_attn = TRUE;
172
 
      serialized_icon = p->alert_icon_serialized;
 
162
      icon = g_themed_icon_new (ICON_ALERT);
173
163
    }
174
164
  else
175
165
    {
176
166
      need_attn = FALSE;
177
 
      serialized_icon = p->default_icon_serialized;
 
167
      icon = g_themed_icon_new (ICON_DEFAULT);
178
168
    }
179
169
 
180
170
  show_name = g_settings_get_boolean (p->indicator_settings,
206
196
  /* build the state */
207
197
  g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}"));
208
198
  g_variant_builder_add (&b, "{sv}", "accessible-desc", g_variant_new_string (a11y));
209
 
  if (serialized_icon != NULL)
210
 
    g_variant_builder_add (&b, "{sv}", "icon", serialized_icon);
 
199
  g_variant_builder_add (&b, "{sv}", "icon", g_icon_serialize (icon));
211
200
  if (label && *label)
212
201
    g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (label));
213
202
  g_variant_builder_add (&b, "{sv}", "visible", g_variant_new_boolean (TRUE));
215
204
 
216
205
  /* cleanup */
217
206
  g_free (a11y);
 
207
  g_object_unref (G_OBJECT (icon));
218
208
 
219
209
  return state;
220
210
}
280
270
}
281
271
 
282
272
static const char *
283
 
get_user_label (const IndicatorSessionUser * user)
284
 
{
285
 
  const char * c;
286
 
 
287
 
  /* If blank or whitespace, use username instead */
288
 
  for (c = user->real_name; *c != '\0' && g_ascii_isspace (*c); c++);
289
 
  if (*c == '\0')
290
 
    return user->user_name;
291
 
 
292
 
  return user->real_name;
293
 
}
294
 
 
295
 
static const char *
296
273
get_current_real_name (IndicatorSessionService * self)
297
274
{
298
275
  GHashTableIter iter;
308
285
    {
309
286
      IndicatorSessionUser * user = value;
310
287
      if (user->is_current_user)
311
 
        return get_user_label (user);
 
288
        return user->real_name;
312
289
    }
313
290
 
314
291
  return "";
454
431
  const IndicatorSessionUser * a = *(const IndicatorSessionUser**)ga;
455
432
  const IndicatorSessionUser * b = *(const IndicatorSessionUser**)gb;
456
433
 
457
 
  if ((i = g_strcmp0 (get_user_label (a), get_user_label (b))))
 
434
  if ((i = g_strcmp0 (a->real_name, b->real_name)))
458
435
    return i;
459
436
 
460
437
  return g_strcmp0 (a->user_name, b->user_name);
461
438
}
462
439
 
463
 
static GVariant *
464
 
serialize_icon_file (const gchar * filename)
465
 
{
466
 
  GVariant * serialized_icon = NULL;
467
 
 
468
 
  if (filename != NULL)
469
 
    {
470
 
      GFile * file = g_file_new_for_path (filename);
471
 
      GIcon * icon = g_file_icon_new (file);
472
 
 
473
 
      serialized_icon = g_icon_serialize (icon);
474
 
 
475
 
      g_object_unref (icon);
476
 
      g_object_unref (file);
477
 
    }
478
 
 
479
 
  return serialized_icon;
480
 
}
481
 
 
482
440
static GMenuModel *
483
441
create_switch_section (IndicatorSessionService * self)
484
442
{
506
464
      item = g_menu_item_new (ellipsis ? _("Switch Account…")
507
465
                                       : _("Switch Account"), action);
508
466
    }
 
467
  else if (g_hash_table_size (p->users) == 1)
 
468
    {
 
469
      const char * action = "indicator.switch-to-greeter";
 
470
      item = g_menu_item_new (_("Lock"), action);
 
471
    }
509
472
  else
510
473
    {
511
 
      const char * action = "indicator.switch-to-screensaver";
512
 
 
513
 
      if (g_hash_table_size (p->users) == 1)
514
 
        item = g_menu_item_new (_("Lock"), action);
515
 
      else
516
 
        item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
517
 
                                         : _("Lock/Switch Account"), action);
 
474
      const char * action = "indicator.switch-to-greeter";
 
475
      item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
 
476
                                       : _("Lock/Switch Account"), action);
518
477
    }
519
478
  str = g_settings_get_string (p->keybinding_settings, "screensaver");
520
479
  g_menu_item_set_attribute (item, "accel", "s", str);
553
512
  for (i=0; i<users->len; ++i)
554
513
    {
555
514
      const IndicatorSessionUser * u = g_ptr_array_index (users, i);
556
 
      GVariant * serialized_icon;
557
 
 
558
 
      item = g_menu_item_new (get_user_label (u), NULL);
 
515
      item = g_menu_item_new (u->real_name, NULL);
559
516
      g_menu_item_set_action_and_target (item, "indicator.switch-to-user", "s", u->user_name);
560
517
      g_menu_item_set_attribute (item, "x-canonical-type", "s", "indicator.user-menu-item");
561
518
 
562
 
      if ((serialized_icon = serialize_icon_file (u->icon_file)))
 
519
      if (u->icon_file != NULL)
563
520
        {
564
 
          g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, serialized_icon);
565
 
          g_variant_unref (serialized_icon);
 
521
          GFile * file = g_file_new_for_path (u->icon_file);
 
522
          GIcon * icon = g_file_icon_new (file);
 
523
          g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, g_icon_serialize (icon));
 
524
          g_clear_object (&icon);
 
525
          g_clear_object (&file);
566
526
        }
567
527
 
568
528
      g_menu_append_item (menu, item);
575
535
}
576
536
 
577
537
static GMenuModel *
578
 
create_logout_section (IndicatorSessionService * self)
 
538
create_session_section (IndicatorSessionService * self, int profile)
579
539
{
580
540
  GMenu * menu;
581
541
  const priv_t * const p = self->priv;
 
542
  GSettings * const s = p->indicator_settings;
582
543
  const gboolean ellipsis = use_ellipsis (self);
583
544
 
584
545
  menu = g_menu_new ();
585
546
 
586
 
  if (indicator_session_actions_can_logout (p->backend_actions))
 
547
  if ((profile == PROFILE_DESKTOP) &&
 
548
      (indicator_session_actions_can_logout (p->backend_actions)))
587
549
    {
588
550
      const char * label = ellipsis ? _("Log Out…") : _("Log Out");
589
551
      g_menu_append (menu, label, "indicator.logout");
590
552
    }
591
553
 
592
 
  return G_MENU_MODEL (menu);
593
 
}
594
 
 
595
 
static GMenuModel *
596
 
create_session_section (IndicatorSessionService * self)
597
 
{
598
 
  GMenu * menu;
599
 
  const priv_t * const p = self->priv;
600
 
  GSettings * const s = p->indicator_settings;
601
 
  const gboolean ellipsis = use_ellipsis (self);
602
 
 
603
 
  menu = g_menu_new ();
604
 
 
605
554
  if (indicator_session_actions_can_suspend (p->backend_actions))
606
555
    g_menu_append (menu, _("Suspend"), "indicator.suspend");
607
556
 
641
590
      sections[n++] = create_admin_section ();
642
591
      sections[n++] = create_settings_section (self);
643
592
      sections[n++] = create_switch_section (self);
644
 
      sections[n++] = create_logout_section (self);
645
 
      sections[n++] = create_session_section (self);
 
593
      sections[n++] = create_session_section (self, profile);
646
594
    }
647
595
  else if (profile == PROFILE_GREETER)
648
596
    {
649
 
      sections[n++] = create_session_section (self);
 
597
      sections[n++] = create_session_section (self, profile);
650
598
    }
651
599
 
652
600
  /* add sections to the submenu */
884
832
      update_switch_actions (self);
885
833
    }
886
834
 
887
 
  if (sections & SECTION_LOGOUT)
888
 
    {
889
 
      rebuild_section (desktop->submenu, 3, create_logout_section(self));
890
 
    }
891
 
 
892
835
  if (sections & SECTION_SESSION)
893
836
    {
894
 
      rebuild_section (desktop->submenu, 4, create_session_section(self));
895
 
      rebuild_section (greeter->submenu, 0, create_session_section(self));
 
837
      rebuild_section (desktop->submenu, 3, create_session_section(self, PROFILE_DESKTOP));
 
838
      rebuild_section (greeter->submenu, 0, create_session_section(self, PROFILE_GREETER));
896
839
    }
897
840
}
898
841
 
1038
981
  GList * uids;
1039
982
  priv_t * p;
1040
983
  gpointer gp;
1041
 
  GIcon * icon;
1042
984
 
1043
985
  /* init our priv pointer */
1044
986
  p = G_TYPE_INSTANCE_GET_PRIVATE (self,
1054
996
                               &p->backend_users,
1055
997
                               &p->backend_guest);
1056
998
 
1057
 
  /* build the serialized icon cache */
1058
 
 
1059
 
  icon = g_themed_icon_new_with_default_fallbacks (ICON_ALERT);
1060
 
  p->alert_icon_serialized = g_icon_serialize (icon);
1061
 
  g_object_unref (icon);
1062
 
 
1063
 
  icon = g_themed_icon_new_with_default_fallbacks (ICON_DEFAULT);
1064
 
  p->default_icon_serialized = g_icon_serialize (icon);
1065
 
  g_object_unref (icon);
1066
 
 
1067
999
  /* init our key-to-User table */
1068
1000
  p->users = g_hash_table_new_full (g_direct_hash,
1069
1001
                                    g_direct_equal,
1099
1031
  g_signal_connect_swapped (gp, "notify",
1100
1032
                            G_CALLBACK(rebuild_switch_section_soon), self);
1101
1033
  g_signal_connect_swapped (gp, "notify",
1102
 
                            G_CALLBACK(rebuild_logout_section_soon), self);
1103
 
  g_signal_connect_swapped (gp, "notify",
1104
1034
                            G_CALLBACK(rebuild_session_section_soon), self);
1105
1035
  g_signal_connect_swapped (gp, "notify::has-online-account-error",
1106
1036
                            G_CALLBACK(rebuild_header_soon), self);
1112
1042
  g_signal_connect_swapped (gp, "changed::suppress-logout-restart-shutdown",
1113
1043
                            G_CALLBACK(rebuild_switch_section_soon), self);
1114
1044
  g_signal_connect_swapped (gp, "changed::suppress-logout-restart-shutdown",
1115
 
                            G_CALLBACK(rebuild_logout_section_soon), self);
1116
 
  g_signal_connect_swapped (gp, "changed::suppress-logout-restart-shutdown",
1117
1045
                            G_CALLBACK(rebuild_session_section_soon), self);
1118
1046
  g_signal_connect_swapped (gp, "changed::suppress-shutdown-menuitem",
1119
1047
                            G_CALLBACK(rebuild_session_section_soon), self);
1225
1153
  g_clear_object (&p->guest_switcher_action);
1226
1154
  g_clear_object (&p->conn);
1227
1155
 
1228
 
  /* clear the serialized icon cache */
1229
 
  g_clear_pointer (&p->alert_icon_serialized, g_variant_unref);
1230
 
  g_clear_pointer (&p->default_icon_serialized, g_variant_unref);
1231
 
 
1232
1156
  G_OBJECT_CLASS (indicator_session_service_parent_class)->dispose (o);
1233
1157
}
1234
1158