static gboolean move_applet (PanelWidget *panel, PanelObjectPackType pack_type, int pack_index, int applet_index) { GSList *applet_list; AppletInfo *info; GtkWidget *parent; applet_list = panel_applet_list_applets (); info = g_slist_nth_data (applet_list, applet_index); if (info == NULL || info->widget == NULL || !panel_applet_can_freely_move (info)) return FALSE; parent = gtk_widget_get_parent (info->widget); if (parent != NULL && PANEL_IS_WIDGET (parent)) { panel_widget_reparent (PANEL_WIDGET (parent), panel, info->widget, pack_type, pack_index); } return TRUE; }
Launcher * find_launcher (const char *path) { GSList *l; g_return_val_if_fail (path != NULL, NULL); for (l = panel_applet_list_applets (); l; l = l->next) { AppletInfo *info = l->data; Launcher *launcher; if (info->type != PANEL_OBJECT_LAUNCHER) continue; launcher = info->data; if (launcher->key_file == NULL) continue; if (launcher->location != NULL && strcmp (launcher->location, path) == 0) return launcher; } return NULL; }
int panel_find_applet_index (GtkWidget *widget) { GSList *applet_list, *l; int i; applet_list = panel_applet_list_applets (); for (i = 0, l = applet_list; l; i++, l = l->next) { AppletInfo *info = l->data; if (info->widget == widget) return i; } return i; }
static gboolean drop_internal_applet (PanelWidget *panel, PanelObjectPackType pack_type, int pack_index, const char *applet_type, int action) { int applet_index = -1; gboolean remove_applet = FALSE; gboolean success = FALSE; if (applet_type == NULL) return FALSE; if (sscanf (applet_type, "MENU:%d", &applet_index) == 1) { if (action != GDK_ACTION_MOVE) g_warning ("Only MOVE supported for menus"); success = move_applet (panel, pack_type, pack_index, applet_index); } else if (strncmp (applet_type, "MENU:", strlen ("MENU:")) == 0) { const char *menu; const char *menu_path; menu = &applet_type[strlen ("MENU:")]; menu_path = strchr (menu, '/'); if (!menu_path) { if (strncmp (menu, "MAIN", strlen ("MAIN")) == 0) success = drop_menu (panel, pack_type, pack_index, NULL, NULL); else success = drop_menu (panel, pack_type, pack_index, menu, NULL); } else { char *menu_filename; menu_filename = g_strndup (menu, menu_path - menu); menu_path++; success = drop_menu (panel, pack_type, pack_index, menu_filename, menu_path); g_free (menu_filename); } } else if (!strncmp (applet_type, "ACTION:", strlen ("ACTION:"))) { if (panel_layout_is_writable ()) { remove_applet = panel_action_button_load_from_drag ( panel->toplevel, pack_type, pack_index, applet_type, &applet_index); success = TRUE; } else { success = FALSE; } } else if (!strcmp (applet_type, "MENUBAR:NEW")) { if (panel_layout_is_writable ()) { panel_menu_bar_create (panel->toplevel, pack_type, pack_index); success = TRUE; } else { success = FALSE; } } else if (!strcmp(applet_type,"SEPARATOR:NEW")) { if (panel_layout_is_writable ()) { panel_separator_create (panel->toplevel, pack_type, pack_index); success = TRUE; } else { success = FALSE; } } else if (!strcmp (applet_type, "USERMENU:NEW")) { if (panel_layout_is_writable ()) { panel_user_menu_create (panel->toplevel, pack_type, pack_index); success = TRUE; } else { success = FALSE; } } else if (!strcmp(applet_type,"LAUNCHER:ASK")) { if (panel_layout_is_writable ()) { ask_about_launcher (NULL, panel, pack_type); success = TRUE; } else { success = FALSE; } } if (remove_applet && action == GDK_ACTION_MOVE) { AppletInfo *info; GSList *applet_list; applet_list = panel_applet_list_applets (); info = g_slist_nth_data (applet_list, applet_index); if (info) panel_layout_delete_object (panel_applet_get_id (info)); } return success; }
static void panel_layout_changed_object (void) { char **ids; GSList *to_remove; gboolean found; const char *id; GSList *l; int i; ids = g_settings_get_strv (layout_settings, PANEL_LAYOUT_OBJECT_ID_LIST_KEY); /* Remove what is not in the layout anymore */ to_remove = NULL; for (l = panel_applet_list_applets (); l != NULL; l = l->next) { id = panel_applet_get_id (l->data); found = FALSE; for (i = 0; ids[i] != NULL; i++) { if (g_strcmp0 (ids[i], id) == 0) { found = TRUE; break; } } if (!found) to_remove = g_slist_prepend (to_remove, l->data); } for (l = to_remove; l != NULL; l = l->next) panel_applet_clean (l->data); g_slist_free (to_remove); /* Add what appeared in the layout */ for (i = 0; ids[i] != NULL; i++) { found = FALSE; if (panel_object_loader_is_queued (ids[i])) continue; for (l = panel_applet_list_applets (); l != NULL; l = l->next) { id = panel_applet_get_id (l->data); if (g_strcmp0 (ids[i], id) == 0) { found = TRUE; break; } } if (!found) panel_layout_load_object (ids[i]); } g_strfreev (ids); /* Always do this, even if there is no object that got loaded: if a * panel has been created, we want a do_load() to unhide it, even if * there is no object to load */ panel_object_loader_do_load (FALSE); }