89
94
gulong mount_added_id;
90
95
gulong mount_changed_id;
91
96
gulong mount_removed_id;
96
99
struct _PanelDesktopMenuItemPrivate {
98
101
PanelWidget *panel;
101
guint append_lock_logout : 1;
103
#ifdef HAVE_TELEPATHY_GLIB
104
GList *presence_items;
105
guint presence_changed_id;
106
TpAccountManager *account_manager;
110
#ifdef HAVE_TELEPATHY_GLIB
112
panel_menu_item_activate_presence (GtkWidget *menuitem,
113
TpAccountManager *account_manager)
115
PanelSessionManagerPresenceType presence_type;
116
TpConnectionPresenceType tp_presence_type;
120
presence_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem),
121
"panel-menu-presence"));
123
panel_session_manager_set_presence (panel_session_manager_get (),
126
tp_presence_type = tp_account_manager_get_most_available_presence (account_manager,
130
if (tp_presence_type == TP_CONNECTION_PRESENCE_TYPE_UNSET ||
131
tp_presence_type == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
132
tp_presence_type == TP_CONNECTION_PRESENCE_TYPE_UNKNOWN ||
133
tp_presence_type == TP_CONNECTION_PRESENCE_TYPE_ERROR)
136
if (presence_type == PANEL_SESSION_MANAGER_PRESENCE_AVAILABLE) {
137
tp_presence_type = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
138
status = "available";
139
} else if (presence_type == PANEL_SESSION_MANAGER_PRESENCE_BUSY) {
140
tp_presence_type = TP_CONNECTION_PRESENCE_TYPE_BUSY;
145
tp_account_manager_set_all_requested_presences (account_manager,
154
panel_menu_item_presence_new (TpAccountManager *account_manager,
155
PanelSessionManagerPresenceType presence_type,
162
if (!account_manager)
165
item = gtk_check_menu_item_new ();
166
setup_menuitem (item, GTK_ICON_SIZE_INVALID, NULL, name);
167
gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
169
/* TODO: we need to add an icon at the right of this CheckMenuItem */
173
image = gtk_image_new_from_icon_name (icon,
174
panel_menu_icon_get_size ());
175
gtk_container_add (GTK_CONTAINER (item), image);
179
g_object_set_data (G_OBJECT (item), "panel-menu-presence",
180
GINT_TO_POINTER (presence_type));
182
g_signal_connect (item, "activate",
183
G_CALLBACK (panel_menu_item_activate_presence),
185
g_signal_connect (G_OBJECT (item), "button_press_event",
186
G_CALLBACK (menu_dummy_button_press_event), NULL);
105
193
activate_uri_on_screen (const char *uri,
106
194
GdkScreen *screen)
348
435
panel_menu_items_create_action_item (PanelActionButtonType action_type)
350
437
return panel_menu_items_create_action_item_full (action_type,
441
#define GDM_FLEXISERVER_COMMAND "gdmflexiserver"
442
#define GDM_FLEXISERVER_ARGS "--startnew"
445
panel_menu_item_activate_switch_user (GtkWidget *menuitem,
451
if (panel_lockdown_get_disable_switch_user_s ())
454
screen = gtk_widget_get_screen (GTK_WIDGET (menuitem));
455
app_info = g_app_info_create_from_commandline (GDM_FLEXISERVER_COMMAND " " GDM_FLEXISERVER_ARGS,
456
GDM_FLEXISERVER_COMMAND,
457
G_APP_INFO_CREATE_NONE,
461
GdkAppLaunchContext *launch_context;
464
display = gdk_screen_get_display (screen);
465
launch_context = gdk_display_get_app_launch_context (display);
466
gdk_app_launch_context_set_screen (launch_context, screen);
468
g_app_info_launch (app_info, NULL,
469
G_APP_LAUNCH_CONTEXT (launch_context),
472
g_object_unref (launch_context);
473
g_object_unref (app_info);
478
panel_menu_items_create_switch_user (gboolean use_icon)
483
item = panel_image_menu_item_new ();
485
item = gtk_image_menu_item_new ();
488
setup_menu_item_with_icon (item, panel_menu_icon_get_size (),
489
NULL, NULL, NULL, _("Switch User"));
491
g_signal_connect (item, "activate",
492
G_CALLBACK (panel_menu_item_activate_switch_user),
494
g_signal_connect (G_OBJECT (item), "button_press_event",
495
G_CALLBACK (menu_dummy_button_press_event), NULL);
1174
1337
panel_place_menu_item_recreate_menu (place_menu);
1178
panel_desktop_menu_item_append_menu (GtkWidget *menu,
1181
PanelDesktopMenuItem *parent;
1182
gboolean add_separator;
1186
parent = PANEL_DESKTOP_MENU_ITEM (data);
1188
add_separator = FALSE;
1189
children = gtk_container_get_children (GTK_CONTAINER (menu));
1190
last = g_list_last (children);
1193
add_separator = !GTK_IS_SEPARATOR (GTK_WIDGET (last->data));
1195
g_list_free (children);
1198
add_menu_separator (menu);
1200
panel_menu_items_append_from_desktop (menu, "yelp.desktop", _("Help and Support"), FALSE);
1202
panel_menu_items_append_from_desktop (menu, "gnome-about.desktop", NULL, FALSE);
1204
if (g_file_test ("/usr/share/omf/about-ubuntu/about-ubuntu-C.omf",
1205
G_FILE_TEST_IS_REGULAR))
1206
panel_menu_items_append_from_desktop (menu, "ubuntu-about.desktop", NULL, FALSE);
1208
if (g_file_test ("/usr/share/omf/about-edubuntu/about-edubuntu-C.omf",
1209
G_FILE_TEST_IS_REGULAR))
1210
panel_menu_items_append_from_desktop (menu, "edubuntu-about.desktop", NULL, FALSE);
1212
if (parent->priv->append_lock_logout)
1213
panel_menu_items_append_lock_logout (menu);
1216
1340
static GtkWidget *
1217
panel_desktop_menu_item_create_menu (PanelDesktopMenuItem *desktop_item)
1341
panel_desktop_menu_item_create_menu (PanelDesktopMenuItem *desktop_item,
1342
gboolean append_lock_logout)
1219
1344
GtkWidget *desktop_menu;
1221
desktop_menu = create_applications_menu ("settings.menu", NULL, FALSE);
1223
g_object_set_data (G_OBJECT (desktop_menu),
1224
"panel-menu-append-callback",
1225
panel_desktop_menu_item_append_menu);
1226
g_object_set_data (G_OBJECT (desktop_menu),
1227
"panel-menu-append-callback-data",
1346
#ifdef HAVE_TELEPATHY_GLIB
1350
desktop_menu = panel_create_menu ();
1352
#ifdef HAVE_TELEPATHY_GLIB
1353
desktop_item->priv->account_manager = tp_account_manager_dup ();
1355
item = panel_menu_item_presence_new (desktop_item->priv->account_manager,
1356
PANEL_SESSION_MANAGER_PRESENCE_AVAILABLE,
1358
PANEL_ICON_USER_AVAILABLE, TRUE);
1360
desktop_item->priv->presence_items = g_list_prepend (desktop_item->priv->presence_items, item);
1361
gtk_menu_shell_append (GTK_MENU_SHELL (desktop_menu), item);
1365
item = panel_menu_item_presence_new (desktop_item->priv->account_manager,
1366
PANEL_SESSION_MANAGER_PRESENCE_BUSY,
1368
PANEL_ICON_USER_BUSY, TRUE);
1370
desktop_item->priv->presence_items = g_list_prepend (desktop_item->priv->presence_items, item);
1371
gtk_menu_shell_append (GTK_MENU_SHELL (desktop_menu), item);
1376
add_menu_separator (desktop_menu);
1379
item = panel_menu_item_desktop_new ("gnome-user-accounts-panel.desktop",
1380
_("My Account"), FALSE);
1382
gtk_menu_shell_append (GTK_MENU_SHELL (desktop_menu), item);
1384
/* Do not force the string like in gnome-shell, but just use the one
1385
* from the .desktop file */
1386
item = panel_menu_item_desktop_new ("gnome-control-center.desktop",
1389
gtk_menu_shell_append (GTK_MENU_SHELL (desktop_menu), item);
1391
if (append_lock_logout)
1392
panel_menu_items_append_lock_logout (desktop_menu);
1230
1394
return desktop_menu;
1234
panel_desktop_menu_item_recreate_menu (PanelDesktopMenuItem *desktop_item)
1236
if (desktop_item->priv->menu) {
1237
gtk_widget_destroy (desktop_item->priv->menu);
1238
desktop_item->priv->menu = panel_desktop_menu_item_create_menu (desktop_item);
1239
gtk_menu_item_set_submenu (GTK_MENU_ITEM (desktop_item),
1240
desktop_item->priv->menu);
1241
panel_applet_menu_set_recurse (GTK_MENU (desktop_item->priv->menu),
1243
desktop_item->priv->panel);
1248
1398
panel_place_menu_item_finalize (GObject *object)
1250
1400
PanelPlaceMenuItem *menuitem = (PanelPlaceMenuItem *) object;
1474
1639
return GTK_WIDGET (menuitem);
1642
#ifdef HAVE_TELEPATHY_GLIB
1644
panel_desktop_menu_item_on_presence_changed (PanelSessionManager *manager,
1645
PanelSessionManagerPresenceType presence_type,
1646
PanelDesktopMenuItem *desktop_item)
1652
switch (presence_type) {
1653
case PANEL_SESSION_MANAGER_PRESENCE_AVAILABLE:
1654
icon = PANEL_ICON_USER_AVAILABLE;
1656
case PANEL_SESSION_MANAGER_PRESENCE_INVISIBLE:
1657
icon = PANEL_ICON_USER_INVISIBLE;
1659
case PANEL_SESSION_MANAGER_PRESENCE_BUSY:
1660
icon = PANEL_ICON_USER_BUSY;
1662
case PANEL_SESSION_MANAGER_PRESENCE_IDLE:
1664
icon = PANEL_ICON_USER_IDLE;
1668
image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (desktop_item));
1669
/* we only have an image if we are specifically using an icon for this
1672
gtk_image_set_from_icon_name (GTK_IMAGE (image),
1673
icon, panel_menu_icon_get_size ());
1676
for (l = desktop_item->priv->presence_items; l != NULL; l = l->next) {
1677
PanelSessionManagerPresenceType for_presence;
1678
GObject *object = l->data;
1680
for_presence = GPOINTER_TO_INT (g_object_get_data (object,
1681
"panel-menu-presence"));
1682
g_signal_handlers_block_by_func (object,
1683
panel_menu_item_activate_presence,
1684
desktop_item->priv->account_manager);
1685
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (object),
1686
for_presence == presence_type);
1687
g_signal_handlers_unblock_by_func (object,
1688
panel_menu_item_activate_presence,
1689
desktop_item->priv->account_manager);
1478
1695
panel_desktop_menu_item_new (gboolean use_image,
1479
1696
gboolean append_lock_logout)
1481
1698
PanelDesktopMenuItem *menuitem;
1700
#ifdef HAVE_TELEPATHY_GLIB
1701
PanelSessionManager *manager;
1484
1704
menuitem = g_object_new (PANEL_TYPE_DESKTOP_MENU_ITEM, NULL);
1487
image = gtk_image_new_from_icon_name ("computer",
1488
panel_menu_icon_get_size ());
1492
setup_menuitem (GTK_WIDGET (menuitem),
1493
image ? panel_menu_icon_get_size () : GTK_ICON_SIZE_INVALID,
1497
menuitem->priv->use_image = use_image;
1499
menuitem->priv->append_lock_logout = append_lock_logout;
1500
if (append_lock_logout)
1501
panel_lockdown_notify_add (G_CALLBACK (panel_desktop_menu_item_recreate_menu),
1504
menuitem->priv->menu = panel_desktop_menu_item_create_menu (menuitem);
1706
name = panel_util_get_user_name ();
1709
#ifdef HAVE_TELEPATHY_GLIB
1710
setup_menu_item_with_icon (GTK_WIDGET (menuitem),
1711
panel_menu_icon_get_size (),
1712
PANEL_ICON_USER_AVAILABLE,
1715
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem),
1718
setup_menu_item_with_icon (GTK_WIDGET (menuitem),
1719
panel_menu_icon_get_size (),
1720
PANEL_ICON_COMPUTER,
1725
setup_menuitem (GTK_WIDGET (menuitem),
1726
GTK_ICON_SIZE_INVALID, NULL,
1731
menuitem->priv->menu = panel_desktop_menu_item_create_menu (menuitem,
1732
append_lock_logout);
1505
1733
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem),
1506
1734
menuitem->priv->menu);
1736
#ifdef HAVE_TELEPATHY_GLIB
1737
manager = panel_session_manager_get ();
1739
menuitem->priv->presence_changed_id =
1740
g_signal_connect (manager,
1742
G_CALLBACK (panel_desktop_menu_item_on_presence_changed),
1745
panel_desktop_menu_item_on_presence_changed (manager,
1746
panel_session_manager_get_presence (manager),
1508
1750
return GTK_WIDGET (menuitem);
1534
1776
"menu_panel", panel);
1537
#define FUSA_APPLET_IID "OAFIID:GNOME_FastUserSwitchApplet"
1538
#define INDICATOR_APPLET_COMPLETE_IID "OAFIID:GNOME_IndicatorAppletComplete"
1541
panel_menu_items_hide_on_fusa (PanelAppletSignaler * pas, AppletInfo * info, GtkWidget * widget)
1543
/* check if we are running stracciatella session */
1544
if (g_strcmp0(g_getenv("GDMSESSION"), "gnome-stracciatella") == 0) {
1545
g_debug("Running stracciatella GNOME session, not touching menu items");
1549
const char * iid = panel_applet_get_iid(info);
1553
if (g_strcmp0(iid, FUSA_APPLET_IID) == 0 ||
1554
g_strcmp0(iid, INDICATOR_APPLET_COMPLETE_IID) == 0)
1555
gtk_widget_hide(widget);
1561
panel_menu_items_show_on_fusa (PanelAppletSignaler * pas, AppletInfo * info, GtkWidget * widget)
1563
/* check if we are running stracciatella session */
1564
if (g_strcmp0(g_getenv("GDMSESSION"), "gnome-stracciatella") == 0) {
1565
g_debug("Running stracciatella GNOME session, not touching menu items");
1569
const char * iid = panel_applet_get_iid(info);
1573
if (g_strcmp0(iid, FUSA_APPLET_IID) == 0 ||
1574
g_strcmp0(iid, INDICATOR_APPLET_COMPLETE_IID) == 0)
1575
gtk_widget_show(widget);
1581
disconnect_signalers (PanelAppletSignaler *signaler,
1584
g_signal_handlers_disconnect_by_func (signaler,
1585
panel_menu_items_hide_on_fusa,
1587
g_signal_handlers_disconnect_by_func (signaler,
1588
panel_menu_items_show_on_fusa,
1780
panel_menu_items_lock_logout_separator_notified (PanelLockdown *lockdown,
1783
GtkWidget *separator = user_data;
1785
if (!panel_lockdown_get_disable_lock_screen (lockdown) ||
1786
!panel_lockdown_get_disable_switch_user (lockdown) ||
1787
!panel_lockdown_get_disable_log_out (lockdown))
1788
gtk_widget_show (separator);
1790
gtk_widget_hide (separator);
1593
1794
panel_menu_items_append_lock_logout (GtkWidget *menu)
1595
gboolean separator_inserted;
1596
1796
GList *children;
1598
1798
GtkWidget *item;
1599
const char *translate;
1602
GtkWidget *separator = NULL;
1603
AppletInfo *fusa = NULL;
1604
PanelAppletSignaler *signaler = panel_applet_signaler_get_default ();
1606
fusa = panel_applet_get_by_iid(FUSA_APPLET_IID);
1608
fusa = panel_applet_get_by_iid(INDICATOR_APPLET_COMPLETE_IID);
1610
separator_inserted = FALSE;
1611
1800
children = gtk_container_get_children (GTK_CONTAINER (menu));
1612
1801
last = g_list_last (children);
1614
separator_inserted = GTK_IS_SEPARATOR (GTK_WIDGET (last->data));
1616
if (separator_inserted) {
1617
g_object_weak_ref (G_OBJECT (last->data),
1618
(GWeakNotify) disconnect_signalers,
1621
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_ADDED,
1622
G_CALLBACK(panel_menu_items_hide_on_fusa), last->data);
1623
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_REMOVED,
1624
G_CALLBACK(panel_menu_items_show_on_fusa), last->data);
1626
gtk_widget_hide(GTK_WIDGET(last->data));
1803
GTK_IS_SEPARATOR (last->data))
1804
item = GTK_WIDGET (last->data);
1806
item = add_menu_separator (menu);
1629
1807
g_list_free (children);
1631
if (panel_lock_screen_action_available ("lock")) {
1632
item = panel_menu_items_create_action_item (PANEL_ACTION_LOCK);
1809
panel_lockdown_on_notify (panel_lockdown_get (),
1812
panel_menu_items_lock_logout_separator_notified,
1814
panel_menu_items_lock_logout_separator_notified (panel_lockdown_get (),
1817
item = panel_menu_items_create_action_item_full (PANEL_ACTION_LOCK,
1820
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1821
g_object_bind_property (panel_lockdown_get (),
1822
"disable-lock-screen",
1825
G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
1828
item = panel_menu_items_create_switch_user (FALSE);
1831
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1832
g_object_bind_property (panel_lockdown_get (),
1833
"disable-switch-user",
1836
G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
1839
item = panel_menu_items_create_action_item_full (PANEL_ACTION_LOGOUT,
1843
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1844
g_object_bind_property (panel_lockdown_get (),
1848
G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
1851
/* FIXME: should be dynamic */
1852
if (panel_session_manager_is_shutdown_available (panel_session_manager_get ())) {
1853
item = panel_menu_items_create_action_item_full (PANEL_ACTION_SHUTDOWN,
1633
1855
if (item != NULL) {
1634
if (!separator_inserted) {
1635
separator = add_menu_separator (menu);
1636
separator_inserted = TRUE;
1858
sep = add_menu_separator (menu);
1639
1860
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1641
g_object_weak_ref (G_OBJECT (item),
1642
(GWeakNotify) disconnect_signalers,
1645
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_ADDED,
1646
G_CALLBACK(panel_menu_items_hide_on_fusa), item);
1647
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_REMOVED,
1648
G_CALLBACK(panel_menu_items_show_on_fusa), item);
1650
gtk_widget_hide(GTK_WIDGET(item));
1655
if (panel_lockdown_get_disable_log_out ())
1657
/* Below this, we only have log out/shutdown items */
1659
/* Translators: translate "1" (msgctxt: "panel:showusername") to anything
1660
* but "1" if "Log Out %s" doesn't make any sense in your
1661
* language (where %s is a username).
1663
translate = C_("panel:showusername", "1");
1664
if (strcmp (translate, "1") == 0) {
1665
const char *user_name;
1667
user_name = g_get_real_name ();
1668
if (!user_name || !user_name [0])
1669
user_name = g_get_user_name ();
1671
/* keep those strings in sync with the ones in
1672
* panel-action-button.c */
1673
/* Translators: this string is used ONLY if you translated
1674
* "1" (msgctxt: "panel:showusername") to "1" */
1675
label = g_strdup_printf (_("Log Out %s..."),
1676
g_get_user_name ());
1677
/* Translators: this string is used ONLY if you translated
1678
* "1" (msgctxt: "panel:showusername") to "1" */
1679
tooltip = g_strdup_printf (_("Log out %s of this session to "
1680
"log in as a different user"),
1687
item = panel_menu_items_create_action_item_full (PANEL_ACTION_LOGOUT,
1693
if (!separator_inserted) {
1694
separator = add_menu_separator (menu);
1695
separator_inserted = TRUE;
1698
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1700
g_object_weak_ref (G_OBJECT (item),
1701
(GWeakNotify) disconnect_signalers,
1704
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_ADDED,
1705
G_CALLBACK(panel_menu_items_hide_on_fusa), item);
1706
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_REMOVED,
1707
G_CALLBACK(panel_menu_items_show_on_fusa), item);
1709
gtk_widget_hide(GTK_WIDGET(item));
1713
item = panel_menu_items_create_action_item (PANEL_ACTION_SHUTDOWN);
1715
if (!separator_inserted)
1716
separator = add_menu_separator (menu);
1718
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1720
g_object_weak_ref (G_OBJECT (item),
1721
(GWeakNotify) disconnect_signalers,
1724
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_ADDED,
1725
G_CALLBACK(panel_menu_items_hide_on_fusa), item);
1726
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_REMOVED,
1727
G_CALLBACK(panel_menu_items_show_on_fusa), item);
1729
gtk_widget_hide(GTK_WIDGET(item));
1733
/* Okay, this is confusing, but required to make the patch
1734
* smaller. Basically if the seperator was created externally it
1735
* gets the signal handlers added when it is detected, but the
1736
* local variable remains NULL. This allows the return in the
1737
* middle to still work. But, if the seperator gets built in the
1738
* remainder of this function then the signal handlers get added
1739
* on here as the local variable becomes a pointer to that created
1740
* seperator. Whew. */
1741
if (separator != NULL) {
1742
g_object_weak_ref (G_OBJECT (separator),
1743
(GWeakNotify) disconnect_signalers,
1746
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_ADDED,
1747
G_CALLBACK(panel_menu_items_hide_on_fusa), separator);
1748
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_REMOVED,
1749
G_CALLBACK(panel_menu_items_show_on_fusa), separator);
1751
gtk_widget_hide(GTK_WIDGET(separator));
1862
g_object_bind_property (panel_lockdown_get (),
1866
G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
1867
g_object_bind_property (panel_lockdown_get (),
1871
G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);