/* * Copyright (C) 2004 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Authors: * Mark McLoughlin */ /* Cheesy little program to find and delete orphaned panel launchers. * Run with "-f" and it will delete the orphans without prompting. * * Compile using: * gcc $(pkg-config --cflags --libs gconf-2.0) cleanup-panel-launchers.c -o cleanup-panel-launchers */ #include #include #include #include int main (int argc, char **argv) { GConfClient *client; GError *error; GSList *id_list; GSList *l; GSList *launcher_list; GSList *orphans; GDir *dir; char *launcher_dir; const char *file; gboolean delete = FALSE; if (argc == 2 && strcmp (argv [1], "-f") == 0) delete = TRUE; g_type_init (); client = gconf_client_get_default (); error = NULL; id_list = gconf_client_get_list (client, "/apps/panel/profiles/default/general/object_id_list", GCONF_VALUE_STRING, &error); if (error != NULL) { g_warning ("Error fetching object_id_list: %s", error->message); g_error_free (error); return 1; } launcher_list = NULL; for (l = id_list; l; l = l->next) { char *id = l->data; char *key; char *type; key = g_strdup_printf ("/apps/panel/profiles/default/objects/%s/object_type", id); type = gconf_client_get_string (client, key, NULL); g_free (key); if (type != NULL && strcmp (type, "launcher-object") == 0) { char *launcher; key = g_strdup_printf ("/apps/panel/profiles/default/objects/%s/launcher_location", id); launcher = gconf_client_get_string (client, key, NULL); g_free (key); if (launcher != NULL) launcher_list = g_slist_prepend (launcher_list, launcher); } g_free (type); g_free (id); } g_slist_free (id_list); launcher_dir = g_strdup_printf ("%s/.gnome2/panel2.d/default/launchers", g_get_home_dir ()); dir = g_dir_open (launcher_dir, 0, &error); if (error) { g_warning ("Unable to read directory '%s': %s\n", launcher_dir, error->message); g_free (error->message); return 1; } orphans = NULL; while ((file = g_dir_read_name (dir))) { if (!g_str_has_suffix (file, ".desktop")) continue; for (l = launcher_list; l; l = l->next) if (strstr (l->data, file)) break; if (l != NULL) continue; orphans = g_slist_prepend (orphans, g_strdup (file)); } g_dir_close (dir); if (orphans != NULL) { if (!delete) { g_print ("Orphaned panel launchers:\n"); for (l = orphans; l; l = l->next) g_print (" %s\n", (char *) l->data); g_print ("\nDelete (y/n)?"); switch (getchar ()) { case 'y': case 'Y': delete = TRUE; break; } } if (delete) { for (l = orphans; l; l = l->next) { char *path; path = g_strdup_printf ("%s/%s", launcher_dir, (char *) l->data); unlink (path); g_free (path); } } for (l = orphans; l; l = l->next) g_free (l->data); g_slist_free (orphans); } else { g_print ("No orphaned launchers found. We're all clean here.\n"); } g_free (launcher_dir); for (l = launcher_list; l; l = l->next) g_free (l->data); g_slist_free (launcher_list); g_object_unref (client); return 0; }