Ejemplo n.º 1
0
static DbusmenuMenuitem *
progress_ui_handler_build_unity_quicklist (NemoProgressUIHandler *self)
{
	g_return_if_fail (self);
	GList *l;

	for (l = unity_quicklist_get_launcher_entries (self->priv->unity_quicklist_handler); l; l = l->next) {
		UnityLauncherEntry *entry = l->data;

		DbusmenuMenuitem *quickmenu = dbusmenu_menuitem_new ();
		dbusmenu_menuitem_property_set (quickmenu,
		                                DBUSMENU_MENUITEM_PROP_LABEL,
			                            UNITY_QUICKLIST_SHOW_COPY_DIALOG);
		dbusmenu_menuitem_property_set_bool (quickmenu,
		                                     DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
		unity_quicklist_handler_append_menuitem (entry, quickmenu);
		g_signal_connect (quickmenu, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
		                  (GCallback) progress_ui_handler_unity_quicklist_show_activated,
			              self);

		quickmenu = dbusmenu_menuitem_new ();
		dbusmenu_menuitem_property_set (quickmenu,
			                            DBUSMENU_MENUITEM_PROP_LABEL,
				                        UNITY_QUICKLIST_CANCEL_COPY);
		dbusmenu_menuitem_property_set_bool (quickmenu,
		                                     DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
		unity_quicklist_handler_append_menuitem (entry, quickmenu);
		g_signal_connect (quickmenu, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
		                  (GCallback) progress_ui_handler_unity_quicklist_cancel_activated,
			              self);
	}
}
static GObject * playlists_menuitem_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	PlaylistsMenuitem * self;
	GeeHashMap* _tmp0_;
	DbusmenuMenuitem* _tmp1_;
	DbusmenuMenuitem* _tmp2_;
	const gchar* _tmp3_ = NULL;
	DbusmenuMenuitem* _tmp4_;
	parent_class = G_OBJECT_CLASS (playlists_menuitem_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = PLAYLISTS_MENUITEM (obj);
	_tmp0_ = gee_hash_map_new (G_TYPE_INT, NULL, NULL, dbusmenu_menuitem_get_type (), (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->current_playlists);
	self->priv->current_playlists = _tmp0_;
	_tmp1_ = dbusmenu_menuitem_new ();
	_g_object_unref0 (self->root_item);
	self->root_item = _tmp1_;
	_tmp2_ = self->root_item;
	_tmp3_ = _ ("Choose Playlist");
	dbusmenu_menuitem_property_set (_tmp2_, DBUSMENU_MENUITEM_PROP_LABEL, _tmp3_);
	_tmp4_ = self->root_item;
	dbusmenu_menuitem_property_set (_tmp4_, DBUSMENU_PLAYLIST_MENUITEM_PATH, "");
	return obj;
}
Ejemplo n.º 3
0
static void
unity_bookmarks_handler_update_bookmarks () {

	NemoBookmark *bookmark;
	guint bookmark_count;
	guint index;
	GList *l;

	/* append new set of bookmarks */
	bookmark_count = nemo_bookmark_list_length (bookmarks);
	for (index = 0; index < bookmark_count; ++index) {

		bookmark = nemo_bookmark_list_item_at (bookmarks, index);

		if (nemo_bookmark_uri_known_not_to_exist (bookmark)) {
			continue;
		}

		for (l = unity_quicklist_get_launcher_entries (unity_quicklist_handler); l; l = l->next) {
			UnityLauncherEntry *entry = l->data;

			DbusmenuMenuitem* menuitem = dbusmenu_menuitem_new();
			gchar *bookmark_name_dbusmenu = eel_str_replace_substring (nemo_bookmark_get_name (bookmark), "_", "__");
			dbusmenu_menuitem_property_set (menuitem, "label", bookmark_name_dbusmenu);
			g_free (bookmark_name_dbusmenu);
			g_signal_connect (menuitem, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
										 (GCallback) activate_bookmark_by_quicklist,
										 bookmark);

			unity_quicklist_handler_append_menuitem (entry, menuitem);
		}
	}
}
Ejemplo n.º 4
0
/* Build the inital status items and start kicking off the async code
   for handling all the statuses */
GList *
status_items_build (StatusUpdateFunc status_update_func)
{
	int i;
	for (i = STATUS_PROVIDER_STATUS_ONLINE; i < STATUS_PROVIDER_STATUS_DISCONNECTED; i++) {
		DbusmenuMenuitem * item = dbusmenu_menuitem_new();

		dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, _(status_strings[i]));
		dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_ICON_NAME, status_icons[i]);

		dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
		dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);

		dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_RADIO);
		dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);

		g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(user_status_change), GINT_TO_POINTER(i));

		menuitems = g_list_append(menuitems, item);
	}

	update_func = status_update_func;

	const gchar * status_providers_env = g_getenv("INDICATOR_MESSAGES_STATUS_PROVIDER_DIR");
	if (status_providers_env == NULL) {
		g_idle_add(provider_directory_parse, STATUS_PROVIDER_DIR);
	} else {
		g_idle_add(provider_directory_parse, (gpointer)status_providers_env);
	}

	return menuitems;
}
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;
}
Ejemplo n.º 7
0
/* Main, is well, main.  It brings everything up and throws
   us into the mainloop of no return. */
int
main (int argc, char ** argv)
{
    g_type_init();

	/* Setting up i18n and gettext.  Apparently, we need
	   all of these. */
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	textdomain (GETTEXT_PACKAGE);

	IndicatorService * service = indicator_service_new_version(INDICATOR_SESSION_DBUS_NAME,
	                                                           INDICATOR_SESSION_DBUS_VERSION);
	g_signal_connect(G_OBJECT(service),
	                 INDICATOR_SERVICE_SIGNAL_SHUTDOWN,
	                 G_CALLBACK(service_shutdown), NULL);

	session_dbus = session_dbus_new();

	g_idle_add(lock_screen_setup, NULL);

    root_menuitem = dbusmenu_menuitem_new();
	g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem));

    dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL);

    rebuild_items (root_menuitem, dbus_interface);

    g_signal_connect (G_OBJECT (dbus_interface),
                      "user-added",
                      G_CALLBACK (user_change),
                      root_menuitem);
    g_signal_connect (G_OBJECT (dbus_interface),
                      "user-removed",
                      G_CALLBACK (user_change),
                      root_menuitem);

	setup_restart_watch();

	setup_up();

    DbusmenuServer * server = dbusmenu_server_new(INDICATOR_SESSION_DBUS_OBJECT);
    dbusmenu_server_set_root(server, root_menuitem);

    mainloop = g_main_loop_new(NULL, FALSE);
    g_main_loop_run(mainloop);

    return 0;
}
Ejemplo n.º 8
0
AbstractLauncherIcon::MenuItemsVector TrashLauncherIcon::GetMenus()
{
  MenuItemsVector result;

  /* Empty Trash */
  glib::Object<DbusmenuMenuitem> menu_item(dbusmenu_menuitem_new());
  dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Empty Trash…"));
  dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, !empty_);
  dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
  empty_activated_signal_.Connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
  [this] (DbusmenuMenuitem*, unsigned timestamp) {
    file_manager_->EmptyTrash(timestamp);
  });

  result.push_back(menu_item);

  return result;
}
void createMenuRootForWnd(WndInfo *wi) {
    if (wi->menuroot != NULL) {
        _releaseMenuItem(wi->menuroot);
        wi->menuroot = NULL;
    }

    wi->menuroot = dbusmenu_menuitem_new();
    if (wi->menuroot == NULL) {
        _error("can't create menuitem for new root");
        return;
    }

    g_object_set_data(G_OBJECT(wi->menuroot), MENUITEM_JHANDLER_PROPERTY, wi->jhandler);
    dbusmenu_menuitem_property_set(wi->menuroot, DBUSMENU_MENUITEM_PROP_LABEL, "DBusMenuRoot");

    if (wi->server == NULL)
        _error("can't set new root because wi->server is null");
    else
        dbusmenu_server_set_root(wi->server, wi->menuroot);
}
Ejemplo n.º 10
0
/* 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);
	}
}
Ejemplo n.º 12
0
WndInfo *registerWindow(guint32 windowXid, jeventcallback handler) {
  // _info("register new window");

  WndInfo *wi = (WndInfo *) malloc(sizeof(WndInfo));
  memset(wi, 0, sizeof(WndInfo));

  wi->xid = (guint32) windowXid;
  wi->menuPath = malloc(64);
  sprintf(wi->menuPath, "/com/canonical/menu/0x%x", windowXid);

  wi->menuroot = dbusmenu_menuitem_new();
  if (wi->menuroot == NULL) {
    _error("can't create menuitem for new root");
    _releaseWindow(wi);
    return NULL;
  }

  g_object_set_data(G_OBJECT(wi->menuroot), MENUITEM_JHANDLER_PROPERTY, handler);
  dbusmenu_menuitem_property_set(wi->menuroot, DBUSMENU_MENUITEM_PROP_LABEL, "DBusMenuRoot");

  wi->server = dbusmenu_server_new(wi->menuPath);
  dbusmenu_server_set_root(wi->server, wi->menuroot);

  wi->registrar = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
                                                G_DBUS_PROXY_FLAGS_NONE,
                                                NULL,
                                                DBUS_NAME,
                                                REG_OBJECT,
                                                REG_IFACE,
                                                NULL, NULL);
  if (wi->registrar == NULL) {
    // probably need to watch for registrar on dbus
    // guint watcher = g_bus_watch_name(G_BUS_TYPE_SESSION, DBUS_NAME, G_BUS_NAME_WATCHER_FLAGS_NONE, on_registrar_available, on_registrar_unavailable);
    _error("can't obtain registrar");
    _releaseWindow(wi);
    return NULL;
  }

  char buf[1024];
  _printWndInfo(wi, buf, 1024);
  _logmsg(LOG_LEVEL_INFO, "new window info: %s", buf);

  GError *error = NULL;
  g_dbus_proxy_call_sync(
    wi->registrar,
    "RegisterWindow",
    g_variant_new("(uo)", windowXid, wi->menuPath),
    G_DBUS_CALL_FLAGS_NONE,
    -1,
    NULL,
    &error);

  if (error != NULL) {
    _logmsg(LOG_LEVEL_ERROR, "Unable to register window, error: %s", error->message);
    g_error_free(error);
    _releaseWindow(wi);
    return NULL;
  }

  wi->jhandler = handler;
  g_signal_connect(wi->registrar, "notify::g-name-owner", G_CALLBACK(_onDbusOwnerChange), wi);

  return wi;
}