DbusmenuMenuitem *addMenuItem(DbusmenuMenuitem *parent, int uid, const char * label, int type, int position) { // _logmsg(LOG_LEVEL_INFO, "add menu item %s (%d) [p %s]", label, uid, _getItemLabel(parent)); DbusmenuMenuitem *item = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set_int(item, MENUITEM_UID_PROPERTY, uid); dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, label); if (type == ITEM_SUBMENU) dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY, DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU); else if (type == ITEM_CHECK) dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK); else if (type == ITEM_RADIO) dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_RADIO); dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_EVENT, G_CALLBACK(_onItemEvent), NULL); g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, G_CALLBACK(_onItemAboutToShow), NULL); // g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_SHOW_TO_USER, G_CALLBACK(_onItemShowToUser), NULL); g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(_onItemActivated), NULL); // g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(_onItemChildAdded), NULL); if (parent != NULL) { gpointer data = g_object_get_data(G_OBJECT(parent), MENUITEM_JHANDLER_PROPERTY); if (data == NULL) _logmsg(LOG_LEVEL_ERROR, "parent of item %d hasn't jhandler", uid); g_object_set_data(G_OBJECT(item), MENUITEM_JHANDLER_PROPERTY, data); if (position < 0) dbusmenu_menuitem_child_append(parent, item); else dbusmenu_menuitem_child_add_position(parent, item, (guint)position); } return item; }
DbusmenuMenuitem* addSeparator(DbusmenuMenuitem * parent, int uid, int position) { DbusmenuMenuitem* item = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TYPE, "separator"); dbusmenu_menuitem_property_set_int(item, MENUITEM_UID_PROPERTY, uid); dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); if (parent != NULL) { if (position < 0) dbusmenu_menuitem_child_append(parent, item); else dbusmenu_menuitem_child_add_position(parent, item, (guint)position); } return item; }
/* Builds up the menu for us */ static void rebuild_items (DbusmenuMenuitem *root, UsersServiceDbus *service) { DbusmenuMenuitem *mi = NULL; DbusmenuMenuitem * guest_mi = NULL; GList *u; UserData *user; gboolean can_activate; gboolean can_lockscreen; GList *children; /* Make sure we have a valid GConf client, and build one if needed */ ensure_gconf_client (); /* Check to see which menu items we're allowed to have */ can_activate = users_service_dbus_can_activate_session (service) && !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); can_lockscreen = !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL); /* Remove the old menu items if that makes sense */ children = dbusmenu_menuitem_take_children (root); g_list_foreach (children, (GFunc)g_object_unref, NULL); g_list_free (children); /* Lock screen item */ if (can_lockscreen) { lock_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); if (shortcut != NULL) { g_debug("Lock screen shortcut: %s", shortcut); dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); g_free(shortcut); } else { g_debug("Unable to get lock screen shortcut."); } g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); dbusmenu_menuitem_child_append(root, lock_menuitem); } /* Set to NULL just incase we don't end up building one */ users_service_dbus_set_guest_item(service, NULL); /* Build all of the user switching items */ if (can_activate == TRUE) { if (can_lockscreen) { DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator1, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator1); } if (check_guest_session ()) { guest_mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (guest_mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); dbusmenu_menuitem_property_set (guest_mi, USER_ITEM_PROP_NAME, _("Guest Session")); dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, FALSE); dbusmenu_menuitem_child_append (root, guest_mi); g_signal_connect (G_OBJECT (guest_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), service); users_service_dbus_set_guest_item(service, guest_mi); } if (check_new_session ()) { switch_menuitem = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (switch_menuitem, DBUSMENU_MENUITEM_PROP_TYPE, MENU_SWITCH_TYPE); dbusmenu_menuitem_property_set (switch_menuitem, MENU_SWITCH_USER, g_get_user_name()); dbusmenu_menuitem_child_append (root, switch_menuitem); g_signal_connect (G_OBJECT (switch_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); } GList * users = NULL; users = users_service_dbus_get_user_list (service); guint user_count = g_list_length(users); if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { users = g_list_sort (users, (GCompareFunc)compare_users_by_username); } for (u = users; u != NULL; u = g_list_next (u)) { user = u->data; user->service = service; if (user->uid == getuid()) { /* Hide me from the list */ continue; } if (g_strcmp0(user->user_name, "guest") == 0) { /* Check to see if the guest has sessions and so therefore should get a check mark. */ if (user->sessions != NULL) { dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, TRUE); } /* If we're showing user accounts, keep going through the list */ if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { continue; } /* If not, we can stop here */ break; } if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); if (user->real_name_conflict) { gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); g_free(conflictedname); } else { dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); } dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_LOGGED_IN, user->sessions != NULL); if (user->icon_url != NULL && user->icon_url[0] != '\0' && g_str_has_prefix(user->icon_url, "file://")) { dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_url + strlen("file://")); } else { dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); } dbusmenu_menuitem_child_append (root, mi); g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); user->menuitem = mi; } } g_list_free(users); } /* If there were a bunch of items before us, we need a separator. */ if (can_lockscreen || can_activate) { DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); } /* Start going through the session based items. */ logout_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { dbusmenu_menuitem_property_set(logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out")); } else { dbusmenu_menuitem_property_set(logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out\342\200\246")); } dbusmenu_menuitem_property_set_bool(logout_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_logout()); dbusmenu_menuitem_child_append(root, logout_mi); g_signal_connect(G_OBJECT(logout_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "logout"); if (can_suspend && allow_suspend) { suspend_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(suspend_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Suspend")); dbusmenu_menuitem_child_append(root, suspend_mi); g_signal_connect(G_OBJECT(suspend_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Suspend"); } if (can_hibernate && allow_hibernate) { hibernate_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(hibernate_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Hibernate")); dbusmenu_menuitem_child_append(root, hibernate_mi); g_signal_connect(G_OBJECT(hibernate_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Hibernate"); } restart_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_TYPE, RESTART_ITEM_TYPE); if (supress_confirmations()) { dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); } else { dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart\342\200\246")); } dbusmenu_menuitem_property_set_bool(restart_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_restart()); dbusmenu_menuitem_child_append(root, restart_mi); g_signal_connect(G_OBJECT(restart_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "restart"); shutdown_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { dbusmenu_menuitem_property_set(shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down")); } else { dbusmenu_menuitem_property_set(shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down\342\200\246")); } dbusmenu_menuitem_property_set_bool(shutdown_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_shutdown()); dbusmenu_menuitem_child_append(root, shutdown_mi); g_signal_connect(G_OBJECT(shutdown_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "shutdown"); RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1); restart_shutdown_logout_mi->logout_mi = logout_mi; restart_shutdown_logout_mi->restart_mi = restart_mi; restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; update_menu_entries(restart_shutdown_logout_mi); /* now add extra launchers */ GDir *extra_launchers_dir; extra_launchers_dir = g_dir_open (EXTRA_LAUNCHER_DIR, 0, NULL); if (extra_launchers_dir != NULL) { GList * launchers = NULL; /* Find all the desktop files we want to use */ for (;;) { const gchar *extra_launcher_file; extra_launcher_file = g_dir_read_name (extra_launchers_dir); if (extra_launcher_file == NULL) break; if (!g_str_has_suffix (extra_launcher_file, ".desktop")) continue; gchar *full_path = g_build_filename (EXTRA_LAUNCHER_DIR, extra_launcher_file, NULL); GAppInfo * appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename (full_path)); g_free (full_path); launchers = g_list_prepend(launchers, appinfo); } g_dir_close(extra_launchers_dir); /* Sort the desktop files based on their names */ launchers = g_list_sort(launchers, sort_app_infos); /* Turn each one into a separate menu item */ GList * launcher = NULL; gboolean sepadded = FALSE; for (launcher = launchers; launcher != NULL; launcher = g_list_next(launcher)) { GAppInfo * appinfo = G_APP_INFO(launcher->data); /* Make sure we have a separator */ if (!sepadded) { DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); g_object_unref(separator); sepadded = TRUE; } /* Build the item */ DbusmenuMenuitem * desktop_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(desktop_mi, DBUSMENU_MENUITEM_PROP_LABEL, g_app_info_get_name(appinfo)); g_signal_connect(G_OBJECT(desktop_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(desktop_activate_cb), appinfo); g_object_weak_ref(G_OBJECT(desktop_mi), (GWeakNotify)g_object_unref, appinfo); /* Put into the menu */ dbusmenu_menuitem_child_append(root, desktop_mi); } g_list_free(launchers); } return; }
void playlists_menuitem_update (PlaylistsMenuitem* self, PlaylistDetails* playlists, int playlists_length1) { PlaylistDetails* _tmp0_; gint _tmp0__length1; g_return_if_fail (self != NULL); _tmp0_ = playlists; _tmp0__length1 = playlists_length1; { PlaylistDetails* detail_collection = NULL; gint detail_collection_length1 = 0; gint _detail_collection_size_ = 0; gint detail_it = 0; detail_collection = _tmp0_; detail_collection_length1 = _tmp0__length1; for (detail_it = 0; detail_it < _tmp0__length1; detail_it = detail_it + 1) { PlaylistDetails _tmp1_ = {0}; PlaylistDetails detail = {0}; playlist_details_copy (&detail_collection[detail_it], &_tmp1_); detail = _tmp1_; { Block2Data* _data2_; gboolean _tmp2_ = FALSE; PlaylistDetails _tmp3_; gboolean _tmp4_ = FALSE; gboolean _tmp7_; DbusmenuMenuitem* _tmp8_; DbusmenuMenuitem* _tmp9_; PlaylistDetails _tmp10_; const gchar* _tmp11_; gchar* _tmp12_ = NULL; gchar* _tmp13_; DbusmenuMenuitem* _tmp14_; DbusmenuMenuitem* _tmp15_; PlaylistDetails _tmp16_; const char* _tmp17_; DbusmenuMenuitem* _tmp18_; DbusmenuMenuitem* _tmp19_; DbusmenuMenuitem* _tmp20_; GeeHashMap* _tmp21_; DbusmenuMenuitem* _tmp22_; gint _tmp23_; gint _tmp24_; DbusmenuMenuitem* _tmp25_; DbusmenuMenuitem* _tmp26_; DbusmenuMenuitem* _tmp27_; PlaylistDetails _tmp28_; const gchar* _tmp29_; _data2_ = g_slice_new0 (Block2Data); _data2_->_ref_count_ = 1; _data2_->self = g_object_ref (self); _tmp3_ = detail; _tmp4_ = playlists_menuitem_already_observed (self, &_tmp3_); if (_tmp4_) { _tmp2_ = TRUE; } else { PlaylistDetails _tmp5_; gboolean _tmp6_ = FALSE; _tmp5_ = detail; _tmp6_ = playlists_menuitem_is_video_related (self, &_tmp5_); _tmp2_ = _tmp6_; } _tmp7_ = _tmp2_; if (_tmp7_) { playlist_details_destroy (&detail); block2_data_unref (_data2_); _data2_ = NULL; continue; } _tmp8_ = dbusmenu_menuitem_new (); _data2_->menuitem = _tmp8_; _tmp9_ = _data2_->menuitem; _tmp10_ = detail; _tmp11_ = _tmp10_.name; _tmp12_ = playlists_menuitem_truncate_item_label_if_needs_be (self, _tmp11_); _tmp13_ = _tmp12_; dbusmenu_menuitem_property_set (_tmp9_, DBUSMENU_MENUITEM_PROP_LABEL, _tmp13_); _g_free0 (_tmp13_); _tmp14_ = _data2_->menuitem; dbusmenu_menuitem_property_set (_tmp14_, DBUSMENU_MENUITEM_PROP_ICON_NAME, "playlist-symbolic"); _tmp15_ = _data2_->menuitem; _tmp16_ = detail; _tmp17_ = _tmp16_.path; dbusmenu_menuitem_property_set (_tmp15_, DBUSMENU_PLAYLIST_MENUITEM_PATH, (const gchar*) _tmp17_); _tmp18_ = _data2_->menuitem; dbusmenu_menuitem_property_set_bool (_tmp18_, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); _tmp19_ = _data2_->menuitem; dbusmenu_menuitem_property_set_bool (_tmp19_, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); _tmp20_ = _data2_->menuitem; g_signal_connect_data (_tmp20_, "item-activated", (GCallback) _____lambda3__dbusmenu_menuitem_item_activated, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0); _tmp21_ = self->priv->current_playlists; _tmp22_ = _data2_->menuitem; _tmp23_ = dbusmenu_menuitem_get_id (_tmp22_); _tmp24_ = _tmp23_; _tmp25_ = _data2_->menuitem; gee_abstract_map_set ((GeeAbstractMap*) _tmp21_, GINT_TO_POINTER (_tmp24_), _tmp25_); _tmp26_ = self->root_item; _tmp27_ = _data2_->menuitem; dbusmenu_menuitem_child_append (_tmp26_, _tmp27_); _tmp28_ = detail; _tmp29_ = _tmp28_.name; g_debug ("playlists-menu-item.vala:66: populating valid playlists %s", _tmp29_); playlist_details_destroy (&detail); block2_data_unref (_data2_); _data2_ = NULL; } } } { GeeHashMap* _tmp30_; GeeCollection* _tmp31_; GeeCollection* _tmp32_; GeeCollection* _tmp33_; GeeIterator* _tmp34_ = NULL; GeeIterator* _tmp35_; GeeIterator* _item_it; _tmp30_ = self->priv->current_playlists; _tmp31_ = gee_abstract_map_get_values ((GeeMap*) _tmp30_); _tmp32_ = _tmp31_; _tmp33_ = _tmp32_; _tmp34_ = gee_iterable_iterator ((GeeIterable*) _tmp33_); _tmp35_ = _tmp34_; _g_object_unref0 (_tmp33_); _item_it = _tmp35_; while (TRUE) { GeeIterator* _tmp36_; gboolean _tmp37_ = FALSE; GeeIterator* _tmp38_; gpointer _tmp39_ = NULL; DbusmenuMenuitem* item; gboolean within; PlaylistDetails* _tmp40_; gint _tmp40__length1; gboolean _tmp46_; _tmp36_ = _item_it; _tmp37_ = gee_iterator_next (_tmp36_); if (!_tmp37_) { break; } _tmp38_ = _item_it; _tmp39_ = gee_iterator_get (_tmp38_); item = (DbusmenuMenuitem*) _tmp39_; within = FALSE; _tmp40_ = playlists; _tmp40__length1 = playlists_length1; { PlaylistDetails* detail_collection = NULL; gint detail_collection_length1 = 0; gint _detail_collection_size_ = 0; gint detail_it = 0; detail_collection = _tmp40_; detail_collection_length1 = _tmp40__length1; for (detail_it = 0; detail_it < _tmp40__length1; detail_it = detail_it + 1) { PlaylistDetails _tmp41_ = {0}; PlaylistDetails detail = {0}; playlist_details_copy (&detail_collection[detail_it], &_tmp41_); detail = _tmp41_; { PlaylistDetails _tmp42_; const char* _tmp43_; DbusmenuMenuitem* _tmp44_; const gchar* _tmp45_ = NULL; _tmp42_ = detail; _tmp43_ = _tmp42_.path; _tmp44_ = item; _tmp45_ = dbusmenu_menuitem_property_get (_tmp44_, DBUSMENU_PLAYLIST_MENUITEM_PATH); if (g_strcmp0 (_tmp43_, _tmp45_) == 0) { within = TRUE; playlist_details_destroy (&detail); break; } playlist_details_destroy (&detail); } } } _tmp46_ = within; if (_tmp46_ == FALSE) { DbusmenuMenuitem* _tmp47_; const gchar* _tmp48_ = NULL; DbusmenuMenuitem* _tmp49_; const gchar* _tmp50_ = NULL; DbusmenuMenuitem* _tmp53_; DbusmenuMenuitem* _tmp54_; _tmp47_ = self->root_item; _tmp48_ = dbusmenu_menuitem_property_get (_tmp47_, DBUSMENU_PLAYLIST_MENUITEM_PATH); _tmp49_ = item; _tmp50_ = dbusmenu_menuitem_property_get (_tmp49_, DBUSMENU_PLAYLIST_MENUITEM_PATH); if (g_strcmp0 (_tmp48_, _tmp50_) == 0) { DbusmenuMenuitem* _tmp51_; const gchar* _tmp52_ = NULL; _tmp51_ = self->root_item; _tmp52_ = _ ("Choose Playlist"); dbusmenu_menuitem_property_set (_tmp51_, DBUSMENU_MENUITEM_PROP_LABEL, _tmp52_); } _tmp53_ = self->root_item; _tmp54_ = item; dbusmenu_menuitem_child_delete (_tmp53_, _tmp54_); } _g_object_unref0 (item); } _g_object_unref0 (_item_it); } }