diff options
Diffstat (limited to 'libslab')
-rw-r--r-- | libslab/Makefile.am | 4 | ||||
-rw-r--r-- | libslab/app-shell.c | 227 | ||||
-rw-r--r-- | libslab/app-shell.h | 11 | ||||
-rw-r--r-- | libslab/application-tile.c | 169 | ||||
-rw-r--r-- | libslab/application-tile.h | 3 | ||||
-rw-r--r-- | libslab/bookmark-agent.c | 41 | ||||
-rw-r--r-- | libslab/directory-tile.c | 669 | ||||
-rw-r--r-- | libslab/directory-tile.h | 61 | ||||
-rw-r--r-- | libslab/document-tile.c | 1130 | ||||
-rw-r--r-- | libslab/document-tile.h | 70 | ||||
-rw-r--r-- | libslab/libslab-utils.c | 196 | ||||
-rw-r--r-- | libslab/libslab-utils.h | 5 | ||||
-rw-r--r-- | libslab/mate-utils.c | 180 | ||||
-rw-r--r-- | libslab/mate-utils.h | 4 | ||||
-rw-r--r-- | libslab/slab-mate-util.c | 158 | ||||
-rw-r--r-- | libslab/slab-mate-util.h | 9 | ||||
-rw-r--r-- | libslab/slab.h | 2 | ||||
-rw-r--r-- | libslab/system-tile.c | 1 |
18 files changed, 35 insertions, 2905 deletions
diff --git a/libslab/Makefile.am b/libslab/Makefile.am index e9cfb986..181d9604 100644 --- a/libslab/Makefile.am +++ b/libslab/Makefile.am @@ -10,8 +10,6 @@ HEADER_FILES= \ app-shell.h \ application-tile.h \ bookmark-agent.h \ - directory-tile.h \ - document-tile.h \ double-click-detector.h \ mate-utils.h \ libslab-utils.h \ @@ -38,8 +36,6 @@ libslab_la_SOURCES = \ app-shell.c \ application-tile.c \ bookmark-agent.c \ - directory-tile.c \ - document-tile.c \ double-click-detector.c \ mate-utils.c \ libslab-utils.c \ diff --git a/libslab/app-shell.c b/libslab/app-shell.c index 0944f404..6e9be346 100644 --- a/libslab/app-shell.c +++ b/libslab/app-shell.c @@ -44,11 +44,11 @@ #define TILE_EXEC_NAME "Tile_desktop_exec_name" #define SECONDS_IN_DAY 86400 -#define EXIT_SHELL_ON_ACTION_START "exit_shell_on_action_start" -#define EXIT_SHELL_ON_ACTION_HELP "exit_shell_on_action_help" -#define EXIT_SHELL_ON_ACTION_ADD_REMOVE "exit_shell_on_action_add_remove" -#define EXIT_SHELL_ON_ACTION_UPGRADE_UNINSTALL "exit_shell_on_action_upgrade_uninstall" -#define NEW_APPS_FILE_KEY "new_apps_file_key" +#define CC_SCHEMA "org.mate.control-center" +#define EXIT_SHELL_ON_ACTION_START "cc-exit-shell-on-action-start" +#define EXIT_SHELL_ON_ACTION_HELP "cc-exit-shell-on-action-help" +#define EXIT_SHELL_ON_ACTION_ADD_REMOVE "cc-exit-shell-on-action-add-remove" +#define EXIT_SHELL_ON_ACTION_UPGRADE_UNINSTALL "cc-exit-shell-on-action-upgrade-uninstall" static void create_application_category_sections (AppShellData * app_data); static GtkWidget *create_filter_section (AppShellData * app_data, const gchar * title); @@ -59,7 +59,6 @@ static GtkWidget *create_actions_section (AppShellData * app_data, const gchar * static void generate_category (const char * category, MateMenuTreeDirectory * root_dir, AppShellData * app_data, gboolean recursive); static void generate_launchers (MateMenuTreeDirectory * root_dir, AppShellData * app_data, CategoryData * cat_data, gboolean recursive); -static void generate_new_apps (AppShellData * app_data); static void insert_launcher_into_category (CategoryData * cat_data, MateDesktopItem * desktop_item, AppShellData * app_data); @@ -842,12 +841,10 @@ matemenu_tree_changed_callback (MateMenuTree * old_tree, gpointer user_data) } AppShellData * -appshelldata_new (const gchar * menu_name, NewAppConfig * new_apps, const gchar * mateconf_keys_prefix, - GtkIconSize icon_size, gboolean show_tile_generic_name, gboolean exit_on_close) +appshelldata_new (const gchar * menu_name, GtkIconSize icon_size, gboolean show_tile_generic_name, gboolean exit_on_close) { AppShellData *app_data = g_new0 (AppShellData, 1); - app_data->mateconf_prefix = mateconf_keys_prefix; - app_data->new_apps = new_apps; + app_data->settings = g_settings_new (CC_SCHEMA); app_data->menu_name = menu_name; app_data->icon_size = icon_size; app_data->stop_incremental_relayout = TRUE; @@ -915,9 +912,6 @@ generate_categories (AppShellData * app_data) } matemenu_tree_item_unref (root_dir); - - if (app_data->new_apps && (app_data->new_apps->max_items > 0)) - generate_new_apps (app_data); } static void @@ -955,8 +949,8 @@ generate_category (const char * category, MateMenuTreeDirectory * root_dir, AppS static gboolean check_specific_apps_hack (MateDesktopItem * item) { - static const gchar *COMMAND_LINE_LOCKDOWN_MATECONF_KEY = - "/desktop/mate/lockdown/disable_command_line"; + static const gchar *COMMAND_LINE_LOCKDOWN_SCHEMA = "org.mate.lockdown"; + static const gchar *COMMAND_LINE_LOCKDOWN_KEY = "disable-command-line"; static const gchar *COMMAND_LINE_LOCKDOWN_DESKTOP_CATEGORY = "TerminalEmulator"; static gboolean got_lockdown_value = FALSE; static gboolean command_line_lockdown; @@ -967,7 +961,10 @@ check_specific_apps_hack (MateDesktopItem * item) if (!got_lockdown_value) { got_lockdown_value = TRUE; - command_line_lockdown = get_slab_mateconf_bool (COMMAND_LINE_LOCKDOWN_MATECONF_KEY); + GSettings *lockdown_settings; + lockdown_settings = g_settings_new (COMMAND_LINE_LOCKDOWN_SCHEMA); + command_line_lockdown = g_settings_get_boolean (lockdown_settings, COMMAND_LINE_LOCKDOWN_KEY); + g_object_unref (lockdown_settings); } /* This seems like an ugly hack but it's the way it's currently done in the old control center */ @@ -1058,184 +1055,6 @@ generate_launchers (MateMenuTreeDirectory * root_dir, AppShellData * app_data, C } static void -generate_new_apps (AppShellData * app_data) -{ - GHashTable *all_apps_cache = NULL; - gchar *all_apps; - GError *error = NULL; - gchar *separator = "\n"; - gchar *mateconf_key; - - gchar *basename; - gchar *all_apps_file_name; - gchar **all_apps_split; - gint x; - gboolean got_new_apps; - CategoryData *new_apps_category = NULL; - GList *categories, *launchers; - GHashTable *new_apps_dups; - - mateconf_key = g_strdup_printf ("%s%s", app_data->mateconf_prefix, NEW_APPS_FILE_KEY); - basename = get_slab_mateconf_string (mateconf_key); - g_free (mateconf_key); - if (!basename) - { - g_warning ("Failure getting mateconf key NEW_APPS_FILE_KEY"); - return; - } - - all_apps_file_name = g_build_filename (g_get_home_dir (), basename, NULL); - g_free (basename); - - if (!g_file_get_contents (all_apps_file_name, &all_apps, NULL, &error)) - { - /* If file does not exist, this is the first time this user has run this, create the baseline file */ - GList *categories, *launchers; - GString *gstr; - gchar *dirname; - - g_error_free (error); - error = NULL; - - /* best initial size determined by running on a couple different platforms */ - gstr = g_string_sized_new (10000); - - for (categories = app_data->categories_list; categories; categories = categories->next) - { - CategoryData *data = categories->data; - for (launchers = data->launcher_list; launchers; launchers = launchers->next) - { - Tile *tile = TILE (launchers->data); - MateDesktopItem *item = - application_tile_get_desktop_item (APPLICATION_TILE (tile)); - const gchar *uri = mate_desktop_item_get_location (item); - g_string_append (gstr, uri); - g_string_append (gstr, separator); - } - } - - dirname = g_path_get_dirname (all_apps_file_name); - g_mkdir_with_parents (dirname, 0700); /* creates if does not exist */ - g_free (dirname); - - if (!g_file_set_contents (all_apps_file_name, gstr->str, -1, &error)) - g_warning ("Error setting all apps file:%s\n", error->message); - - g_string_free (gstr, TRUE); - g_free (all_apps_file_name); - return; - } - - all_apps_cache = g_hash_table_new (g_str_hash, g_str_equal); - all_apps_split = g_strsplit (all_apps, separator, -1); - for (x = 0; all_apps_split[x]; x++) - { - g_hash_table_insert (all_apps_cache, all_apps_split[x], all_apps_split[x]); - } - - got_new_apps = FALSE; - new_apps_dups = g_hash_table_new (g_str_hash, g_str_equal); - for (categories = app_data->categories_list; categories; categories = categories->next) - { - CategoryData *cat_data = categories->data; - for (launchers = cat_data->launcher_list; launchers; launchers = launchers->next) - { - Tile *tile = TILE (launchers->data); - MateDesktopItem *item = - application_tile_get_desktop_item (APPLICATION_TILE (tile)); - const gchar *uri = mate_desktop_item_get_location (item); - if (!g_hash_table_lookup (all_apps_cache, uri)) - { - GFile *file; - GFileInfo *info; - long filetime; - - if (g_hash_table_lookup (new_apps_dups, uri)) - { - /* if a desktop file is in 2 or more top level categories, only show it once */ - /* printf("Discarding Newapp duplicate:%s\n", uri); */ - break; - } - g_hash_table_insert (new_apps_dups, (gpointer) uri, (gpointer) uri); - - if (!got_new_apps) - { - new_apps_category = g_new0 (CategoryData, 1); - new_apps_category->category = - g_strdup (app_data->new_apps->name); - app_data->new_apps->garray = - g_array_sized_new (FALSE, TRUE, - sizeof (NewAppData *), - app_data->new_apps->max_items); - - /* should not need this, but a bug in glib does not actually clear the elements until you call this method */ - g_array_set_size (app_data->new_apps->garray, app_data->new_apps->max_items); - got_new_apps = TRUE; - } - - file = g_file_new_for_uri (uri); - info = g_file_query_info (file, - G_FILE_ATTRIBUTE_TIME_MODIFIED, - 0, NULL, NULL); - - if (!info) - { - g_object_unref (file); - g_warning ("Cant get vfs info for %s\n", uri); - return; - } - filetime = (long) g_file_info_get_attribute_uint64 (info, - G_FILE_ATTRIBUTE_TIME_MODIFIED); - g_object_unref (info); - g_object_unref (file); - - for (x = 0; x < app_data->new_apps->max_items; x++) - { - NewAppData *temp_data = (NewAppData *) - g_array_index (app_data->new_apps->garray, NewAppData *, x); - if (!temp_data || filetime > temp_data->time) /* if this slot is empty or we are newer than this slot */ - { - NewAppData *temp = g_new0 (NewAppData, 1); - temp->time = filetime; - temp->item = item; - g_array_insert_val (app_data->new_apps->garray, x, - temp); - break; - } - } - } - } - } - g_hash_table_destroy (new_apps_dups); - g_hash_table_destroy (all_apps_cache); - - if (got_new_apps) - { - for (x = 0; x < app_data->new_apps->max_items; x++) - { - NewAppData *data = - (NewAppData *) g_array_index (app_data->new_apps->garray, - NewAppData *, x); - if (data) - { - insert_launcher_into_category (new_apps_category, data->item, - app_data); - g_free (data); - } - else - break; - } - app_data->categories_list = - g_list_prepend (app_data->categories_list, new_apps_category); - - g_array_free (app_data->new_apps->garray, TRUE); - } - g_free (all_apps); - g_free (all_apps_file_name); - g_strfreev (all_apps_split); -} - -static void insert_launcher_into_category (CategoryData * cat_data, MateDesktopItem * desktop_item, AppShellData * app_data) { @@ -1251,7 +1070,7 @@ insert_launcher_into_category (CategoryData * cat_data, MateDesktopItem * deskto launcher = application_tile_new_full (mate_desktop_item_get_location (desktop_item), - app_data->icon_size, app_data->show_tile_generic_name, app_data->mateconf_prefix); + app_data->icon_size, app_data->show_tile_generic_name); gtk_widget_set_size_request (launcher, SIZING_TILE_WIDTH, -1); filepath = @@ -1350,19 +1169,16 @@ static void handle_launcher_single_clicked (Tile * launcher, gpointer data) { AppShellData *app_data = (AppShellData *) data; - gchar *mateconf_key; tile_trigger_action (launcher, launcher->actions[APPLICATION_TILE_ACTION_START]); - mateconf_key = g_strdup_printf ("%s%s", app_data->mateconf_prefix, EXIT_SHELL_ON_ACTION_START); - if (get_slab_mateconf_bool (mateconf_key)) + if (g_settings_get_boolean (app_data->settings, EXIT_SHELL_ON_ACTION_START)) { if (app_data->exit_on_close) gtk_main_quit (); else hide_shell (app_data); } - g_free (mateconf_key); } static void @@ -1375,38 +1191,35 @@ handle_menu_action_performed (Tile * launcher, TileEvent * event, TileAction * a temp = NULL; if (action == launcher->actions[APPLICATION_TILE_ACTION_START]) { - temp = g_strdup_printf ("%s%s", app_data->mateconf_prefix, EXIT_SHELL_ON_ACTION_START); + temp = EXIT_SHELL_ON_ACTION_START; } else if (action == launcher->actions[APPLICATION_TILE_ACTION_HELP]) { - temp = g_strdup_printf ("%s%s", app_data->mateconf_prefix, EXIT_SHELL_ON_ACTION_HELP); + temp = EXIT_SHELL_ON_ACTION_HELP; } else if (action == launcher->actions[APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU] || action == launcher->actions[APPLICATION_TILE_ACTION_UPDATE_STARTUP]) { - temp = g_strdup_printf ("%s%s", app_data->mateconf_prefix, - EXIT_SHELL_ON_ACTION_ADD_REMOVE); + temp = EXIT_SHELL_ON_ACTION_ADD_REMOVE; } else if (action == launcher->actions[APPLICATION_TILE_ACTION_UPGRADE_PACKAGE] || action == launcher->actions[APPLICATION_TILE_ACTION_UNINSTALL_PACKAGE]) { - temp = g_strdup_printf ("%s%s", app_data->mateconf_prefix, - EXIT_SHELL_ON_ACTION_UPGRADE_UNINSTALL); + temp = EXIT_SHELL_ON_ACTION_UPGRADE_UNINSTALL; } if (temp) { - if (get_slab_mateconf_bool (temp)) + if (g_settings_get_boolean (app_data->settings, temp)) { if (app_data->exit_on_close) gtk_main_quit (); else hide_shell (app_data); } - g_free (temp); } else g_warning ("Unknown Action"); diff --git a/libslab/app-shell.h b/libslab/app-shell.h index 309965a3..d7032c2a 100644 --- a/libslab/app-shell.h +++ b/libslab/app-shell.h @@ -23,6 +23,7 @@ #include <glib.h> #include <gtk/gtk.h> +#include <gio/gio.h> #define MATEMENU_I_KNOW_THIS_IS_UNSTABLE #include <matemenu-tree.h> #include <libmate/mate-desktop-item.h> @@ -82,9 +83,7 @@ typedef struct _AppShellData Tile *last_clicked_launcher; SlabSection *selected_group; GtkIconSize icon_size; - const gchar *mateconf_prefix; const gchar *menu_name; - NewAppConfig *new_apps; MateMenuTree *tree; GHashTable *hash; @@ -97,6 +96,8 @@ typedef struct _AppShellData gboolean show_tile_generic_name; gboolean exit_on_close; + + GSettings *settings; } AppShellData; typedef struct @@ -123,10 +124,8 @@ typedef struct void generate_categories (AppShellData * app_data); -/* If new_apps is NULL then the new applications category is not created */ -AppShellData *appshelldata_new (const gchar * menu_name, NewAppConfig * new_apps, - const gchar * mateconf_keys_prefix, GtkIconSize icon_size, - gboolean show_tile_generic_name, gboolean exit_on_close); +AppShellData *appshelldata_new (const gchar * menu_name, + GtkIconSize icon_size, gboolean show_tile_generic_name, gboolean exit_on_close); void layout_shell (AppShellData * app_data, const gchar * filter_title, const gchar * groups_title, const gchar * actions_title, GSList * actions, diff --git a/libslab/application-tile.c b/libslab/application-tile.c index 81a1e373..c2c5ff31 100644 --- a/libslab/application-tile.c +++ b/libslab/application-tile.c @@ -25,7 +25,6 @@ #include <glib.h> #include <glib/gi18n-lib.h> #include <glib/gstdio.h> -#include <mateconf/mateconf-client.h> #include <unistd.h> #include "slab-mate-util.h" @@ -45,7 +44,7 @@ static void application_tile_get_property (GObject *, guint, GValue *, GPa static void application_tile_set_property (GObject *, guint, const GValue *, GParamSpec *); static void application_tile_finalize (GObject *); -static void application_tile_setup (ApplicationTile *, const gchar *); +static void application_tile_setup (ApplicationTile *); static GtkWidget *create_header (const gchar *); static GtkWidget *create_subheader (const gchar *); @@ -56,17 +55,12 @@ static void start_trigger (Tile *, TileEvent *, TileAction *); static void help_trigger (Tile *, TileEvent *, TileAction *); static void user_apps_trigger (Tile *, TileEvent *, TileAction *); static void startup_trigger (Tile *, TileEvent *, TileAction *); -static void upgrade_trigger (Tile *, TileEvent *, TileAction *); -static void uninstall_trigger (Tile *, TileEvent *, TileAction *); static void add_to_user_list (ApplicationTile *); static void remove_from_user_list (ApplicationTile *); static void add_to_startup_list (ApplicationTile *); static void remove_from_startup_list (ApplicationTile *); -static gboolean verify_package_management_command (const gchar *); -static void run_package_management_command (ApplicationTile *, gchar *); - static void update_user_list_menu_item (ApplicationTile *); static void agent_notify_cb (GObject *, GParamSpec *, gpointer); @@ -94,8 +88,7 @@ typedef struct { enum { PROP_0, PROP_APPLICATION_NAME, - PROP_APPLICATION_DESCRIPTION, - PROP_APPLICATION_MATECONF_PREFIX + PROP_APPLICATION_DESCRIPTION }; static void @@ -122,24 +115,17 @@ application_tile_class_init (ApplicationTileClass *app_tile_class) "application-description", "application-description", "the name of the application", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - g_obj_class, PROP_APPLICATION_MATECONF_PREFIX, - g_param_spec_string ( - "mateconf-prefix", "mateconf-prefix", - "configuration prefix", NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); } GtkWidget * application_tile_new (const gchar *desktop_item_id) { - return application_tile_new_full (desktop_item_id, GTK_ICON_SIZE_DND, TRUE, NULL); + return application_tile_new_full (desktop_item_id, GTK_ICON_SIZE_DND, TRUE); } GtkWidget * application_tile_new_full (const gchar *desktop_item_id, - GtkIconSize image_size, gboolean show_generic_name, const gchar *mateconf_prefix) + GtkIconSize image_size, gboolean show_generic_name) { ApplicationTile *this; ApplicationTilePrivate *priv; @@ -171,7 +157,7 @@ application_tile_new_full (const gchar *desktop_item_id, priv->desktop_item = desktop_item; priv->show_generic_name = show_generic_name; - application_tile_setup (this, mateconf_prefix); + application_tile_setup (this); return GTK_WIDGET (this); } @@ -190,7 +176,7 @@ application_tile_init (ApplicationTile *tile) priv->is_bookmarked = FALSE; priv->notify_signal_id = 0; - tile->name = tile->description = tile->mateconf_prefix = NULL; + tile->name = tile->description = NULL; } static void @@ -207,10 +193,6 @@ application_tile_finalize (GObject *g_object) g_free (tile->description); tile->description = NULL; } - if (tile->mateconf_prefix) { - g_free (tile->mateconf_prefix); - tile->mateconf_prefix = NULL; - } if (priv->desktop_item) { mate_desktop_item_unref (priv->desktop_item); @@ -243,10 +225,6 @@ application_tile_get_property (GObject *g_obj, guint prop_id, GValue *value, GPa g_value_set_string (value, tile->description); break; - case PROP_APPLICATION_MATECONF_PREFIX: - g_value_set_string (value, tile->mateconf_prefix); - break; - default: break; } @@ -270,19 +248,13 @@ application_tile_set_property (GObject *g_obj, guint prop_id, const GValue *valu tile->description = g_strdup (g_value_get_string (value)); break; - case PROP_APPLICATION_MATECONF_PREFIX: - if (tile->mateconf_prefix) - g_free (tile->mateconf_prefix); - tile->mateconf_prefix = g_strdup (g_value_get_string (value)); - break; - default: break; } } static void -application_tile_setup (ApplicationTile *this, const gchar *mateconf_prefix) +application_tile_setup (ApplicationTile *this) { ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this); @@ -306,11 +278,6 @@ application_tile_setup (ApplicationTile *this, const gchar *mateconf_prefix) gchar *markup; gchar *str; - /*Fixme - need to address the entire mateconf key location issue */ - /*Fixme - this is just a temporary stop gap */ - gboolean use_new_prefix; - - if (! priv->desktop_item) { priv->desktop_item = load_desktop_item_from_unknown (TILE (this)->uri); @@ -350,7 +317,6 @@ application_tile_setup (ApplicationTile *this, const gchar *mateconf_prefix) "context-menu", context_menu, "application-name", name, "application-description", desc, - "mateconf-prefix", mateconf_prefix, NULL); gtk_widget_set_tooltip_text (GTK_WIDGET (this), comment); @@ -426,41 +392,6 @@ application_tile_setup (ApplicationTile *this, const gchar *mateconf_prefix) gtk_container_add (menu_ctnr, menu_item); } -/* make upgrade action */ - - if (this->mateconf_prefix && ! g_str_has_prefix (this->mateconf_prefix, "/desktop/")) - use_new_prefix = TRUE; - else - use_new_prefix = FALSE; - - if(!use_new_prefix) - key = SLAB_UPGRADE_PACKAGE_KEY; - else - key = "/apps/main-menu/upgrade_package_command"; - - if (verify_package_management_command (key)) { - action = tile_action_new (TILE (this), upgrade_trigger, _("Upgrade"), TILE_ACTION_OPENS_NEW_WINDOW); - actions [APPLICATION_TILE_ACTION_UPGRADE_PACKAGE] = action; - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - } else - actions [APPLICATION_TILE_ACTION_UPGRADE_PACKAGE] = NULL; - -/* make uninstall action */ - - if(!use_new_prefix) - key = SLAB_UNINSTALL_PACKAGE_KEY; - else - key = "/apps/main-menu/uninstall_package_command"; - - if (verify_package_management_command (key)) { - action = tile_action_new (TILE (this), uninstall_trigger, _("Uninstall"), TILE_ACTION_OPENS_NEW_WINDOW); - actions [APPLICATION_TILE_ACTION_UNINSTALL_PACKAGE] = action; - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - } else - actions [APPLICATION_TILE_ACTION_UNINSTALL_PACKAGE] = NULL; - gtk_widget_show_all (GTK_WIDGET (TILE (this)->context_menu)); } @@ -555,92 +486,6 @@ remove_from_user_list (ApplicationTile *this) } static void -upgrade_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - run_package_management_command (APPLICATION_TILE (tile), SLAB_UPGRADE_PACKAGE_KEY); -} - -static void -uninstall_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - run_package_management_command (APPLICATION_TILE (tile), SLAB_UNINSTALL_PACKAGE_KEY); -} - -static gboolean -verify_package_management_command (const gchar *mateconf_key) -{ - gchar *cmd; - gchar *path; - gchar *args; - - gboolean retval; - - cmd = get_slab_mateconf_string (mateconf_key); - if (!cmd) - return FALSE; - - args = strchr (cmd, ' '); - - if (args) - *args = '\0'; - - path = g_find_program_in_path (cmd); - - retval = (path != NULL); - - g_free (cmd); - g_free (path); - - return retval; -} - -static void -run_package_management_command (ApplicationTile *tile, gchar *mateconf_key) -{ - ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (tile); - - gchar *cmd_precis; - gchar *package_name; - - GString *cmd; - gint pivot; - gchar **argv; - - GError *error = NULL; - - package_name = get_package_name_from_desktop_item (priv->desktop_item); - - if (!package_name) - return; - - cmd_precis = get_slab_mateconf_string (mateconf_key); - - g_assert (cmd_precis); - - pivot = strstr (cmd_precis, "PACKAGE_NAME") - cmd_precis; - - cmd = g_string_new_len (cmd_precis, pivot); - g_string_append (cmd, package_name); - g_string_append (cmd, & cmd_precis [pivot + 12]); - - argv = g_strsplit (cmd->str, " ", -1); - - g_string_free (cmd, TRUE); - - g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error); - - if (error) { - g_warning ("error: [%s]\n", error->message); - - g_error_free (error); - } - - g_free (cmd_precis); - g_free (package_name); - g_strfreev (argv); -} - -static void startup_trigger (Tile *tile, TileEvent *event, TileAction *action) { ApplicationTile *this = APPLICATION_TILE (tile); diff --git a/libslab/application-tile.h b/libslab/application-tile.h index 612e8760..dc2eb8b0 100644 --- a/libslab/application-tile.h +++ b/libslab/application-tile.h @@ -48,7 +48,6 @@ typedef struct gchar *name; gchar *description; - gchar *mateconf_prefix; } ApplicationTile; typedef struct @@ -60,7 +59,7 @@ GType application_tile_get_type (void); GtkWidget *application_tile_new (const gchar * desktop_item_id); GtkWidget *application_tile_new_full (const gchar * desktop_item_id, - GtkIconSize icon_size, gboolean show_generic_name, const gchar *mateconf_prefix); + GtkIconSize icon_size, gboolean show_generic_name); MateDesktopItem *application_tile_get_desktop_item (ApplicationTile * tile); diff --git a/libslab/bookmark-agent.c b/libslab/bookmark-agent.c index 8e646a72..b78db7b7 100644 --- a/libslab/bookmark-agent.c +++ b/libslab/bookmark-agent.c @@ -36,11 +36,6 @@ #include "libslab-utils.h" -#define MODIFIABLE_APPS_MATECONF_KEY "/desktop/mate/applications/main-menu/lock-down/user_modifiable_apps" -#define MODIFIABLE_DOCS_MATECONF_KEY "/desktop/mate/applications/main-menu/lock-down/user_modifiable_docs" -#define MODIFIABLE_DIRS_MATECONF_KEY "/desktop/mate/applications/main-menu/lock-down/user_modifiable_dirs" -#define MODIFIABLE_SYS_MATECONF_KEY "/desktop/mate/applications/main-menu/lock-down/user_modifiable_system_area" - #define USER_APPS_STORE_FILE_NAME "applications.xbel" #define USER_DOCS_STORE_FILE_NAME "documents.xbel" #define USER_DIRS_STORE_FILE_NAME "places.xbel" @@ -67,11 +62,9 @@ typedef struct { gboolean user_modifiable; gboolean reorderable; const gchar *store_filename; - const gchar *lockdown_key; GFileMonitor *store_monitor; GFileMonitor *user_store_monitor; - guint mateconf_monitor; void (* update_path) (BookmarkAgent *); void (* load_store) (BookmarkAgent *); @@ -119,7 +112,6 @@ static void create_dir_item (BookmarkAgent *, const gchar *); static void store_monitor_cb (GFileMonitor *, GFile *, GFile *, GFileMonitorEvent, gpointer); -static void mateconf_notify_cb (MateConfClient *, guint, MateConfEntry *, gpointer); static void weak_destroy_cb (gpointer, GObject *); static gint recent_item_mru_comp_func (gconstpointer a, gconstpointer b); @@ -469,11 +461,9 @@ bookmark_agent_init (BookmarkAgent *this) priv->user_modifiable = FALSE; priv->reorderable = FALSE; priv->store_filename = NULL; - priv->lockdown_key = NULL; priv->store_monitor = NULL; priv->user_store_monitor = NULL; - priv->mateconf_monitor = 0; priv->update_path = NULL; priv->load_store = NULL; @@ -499,25 +489,22 @@ bookmark_agent_new (BookmarkStoreType type) switch (type) { case BOOKMARK_STORE_USER_APPS: - priv->lockdown_key = MODIFIABLE_APPS_MATECONF_KEY; priv->store_filename = USER_APPS_STORE_FILE_NAME; priv->create_item = create_app_item; break; case BOOKMARK_STORE_USER_DOCS: - priv->lockdown_key = MODIFIABLE_DOCS_MATECONF_KEY; priv->store_filename = USER_DOCS_STORE_FILE_NAME; priv->create_item = create_doc_item; break; case BOOKMARK_STORE_USER_DIRS: - priv->lockdown_key = MODIFIABLE_DIRS_MATECONF_KEY; priv->store_filename = USER_DIRS_STORE_FILE_NAME; priv->create_item = create_dir_item; - priv->user_modifiable = GPOINTER_TO_INT (libslab_get_mateconf_value (priv->lockdown_key)); + priv->user_modifiable = TRUE; priv->reorderable = FALSE; priv->load_store = load_places_store; @@ -545,7 +532,6 @@ bookmark_agent_new (BookmarkStoreType type) break; case BOOKMARK_STORE_SYSTEM: - priv->lockdown_key = MODIFIABLE_SYS_MATECONF_KEY; priv->store_filename = SYSTEM_STORE_FILE_NAME; priv->create_item = create_app_item; @@ -559,15 +545,12 @@ bookmark_agent_new (BookmarkStoreType type) type == BOOKMARK_STORE_USER_APPS || type == BOOKMARK_STORE_USER_DOCS || type == BOOKMARK_STORE_USER_DIRS || type == BOOKMARK_STORE_SYSTEM) { - priv->user_modifiable = GPOINTER_TO_INT (libslab_get_mateconf_value (priv->lockdown_key)); + priv->user_modifiable = TRUE; priv->user_store_path = g_build_filename ( g_get_user_data_dir (), PACKAGE, priv->store_filename, NULL); priv->update_path = update_user_spec_path; - - priv->mateconf_monitor = libslab_mateconf_notify_add ( - priv->lockdown_key, mateconf_notify_cb, this); } if (type == BOOKMARK_STORE_USER_APPS || type == BOOKMARK_STORE_USER_DOCS || type == BOOKMARK_STORE_SYSTEM) { @@ -640,8 +623,6 @@ finalize (GObject *g_obj) g_object_unref (priv->gtk_store_monitor); } - libslab_mateconf_notify_remove (priv->mateconf_monitor); - g_bookmark_file_free (priv->store); G_OBJECT_CLASS (bookmark_agent_parent_class)->finalize (g_obj); @@ -1245,24 +1226,6 @@ store_monitor_cb (GFileMonitor *mon, GFile *f1, GFile *f2, } static void -mateconf_notify_cb (MateConfClient *client, guint conn_id, - MateConfEntry *entry, gpointer user_data) -{ - BookmarkAgent *this = BOOKMARK_AGENT (user_data); - BookmarkAgentPrivate *priv = PRIVATE (this); - - gboolean user_modifiable; - - - user_modifiable = GPOINTER_TO_INT (libslab_get_mateconf_value (priv->lockdown_key)); - - if (priv->user_modifiable != user_modifiable) { - priv->user_modifiable = user_modifiable; - update_agent (this); - } -} - -static void weak_destroy_cb (gpointer data, GObject *g_obj) { instances [GPOINTER_TO_INT (data)] = NULL; diff --git a/libslab/directory-tile.c b/libslab/directory-tile.c deleted file mode 100644 index 00957e81..00000000 --- a/libslab/directory-tile.c +++ /dev/null @@ -1,669 +0,0 @@ -/* - * This file is part of libtile. - * - * Copyright (c) 2006 Novell, Inc. - * - * Libtile is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Libtile 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 Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libslab; if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "directory-tile.h" -#include "config.h" - -#include <glib/gi18n-lib.h> -#include <string.h> -#include <gio/gio.h> -#include <gdk/gdk.h> -#include <unistd.h> - -#include "slab-mate-util.h" -#include "mate-utils.h" -#include "libslab-utils.h" - -#define MATECONF_SEND_TO_CMD_KEY "/desktop/mate/applications/main-menu/file-area/file_send_to_cmd" -#define MATECONF_ENABLE_DELETE_KEY_DIR "/apps/caja/preferences" -#define MATECONF_ENABLE_DELETE_KEY MATECONF_ENABLE_DELETE_KEY_DIR "/enable_delete" -#define MATECONF_CONFIRM_DELETE_KEY MATECONF_ENABLE_DELETE_KEY_DIR "/confirm_trash" - -G_DEFINE_TYPE (DirectoryTile, directory_tile, NAMEPLATE_TILE_TYPE) - -static void directory_tile_finalize (GObject *); -static void directory_tile_style_set (GtkWidget *, GtkStyle *); - -static void directory_tile_private_setup (DirectoryTile *); -static void load_image (DirectoryTile *); - -static GtkWidget *create_header (const gchar *); - -static void header_size_allocate_cb (GtkWidget *, GtkAllocation *, gpointer); - -static void open_with_default_trigger (Tile *, TileEvent *, TileAction *); -static void rename_trigger (Tile *, TileEvent *, TileAction *); -static void move_to_trash_trigger (Tile *, TileEvent *, TileAction *); -static void delete_trigger (Tile *, TileEvent *, TileAction *); -static void send_to_trigger (Tile *, TileEvent *, TileAction *); - -static void rename_entry_activate_cb (GtkEntry *, gpointer); -static gboolean rename_entry_key_release_cb (GtkWidget *, GdkEventKey *, gpointer); -static void mateconf_enable_delete_cb (MateConfClient *, guint, MateConfEntry *, gpointer); - -static void disown_spawned_child (gpointer); - -typedef struct -{ - gchar *basename; - gchar *mime_type; - gchar *icon_name; - - GtkBin *header_bin; - GAppInfo *default_app; - - gboolean image_is_broken; - - gboolean delete_enabled; - guint mateconf_conn_id; -} DirectoryTilePrivate; - -#define DIRECTORY_TILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DIRECTORY_TILE_TYPE, DirectoryTilePrivate)) - -static void directory_tile_class_init (DirectoryTileClass *this_class) -{ - GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (this_class); - - g_obj_class->finalize = directory_tile_finalize; - - widget_class->style_set = directory_tile_style_set; - - g_type_class_add_private (this_class, sizeof (DirectoryTilePrivate)); -} - -GtkWidget * -directory_tile_new (const gchar *in_uri, const gchar *title, const gchar *icon_name, const gchar *mime_type) -{ - DirectoryTile *this; - DirectoryTilePrivate *priv; - - gchar *uri; - GtkWidget *image; - GtkWidget *header; - GtkMenu *context_menu; - - GtkContainer *menu_ctnr; - GtkWidget *menu_item; - - TileAction *action; - - gchar *basename; - - gchar *markup; - - AtkObject *accessible; - - gchar *filename; - gchar *tooltip_text; - - - uri = g_strdup (in_uri); - - image = gtk_image_new (); - - if (! title) { - markup = g_path_get_basename (uri); - basename = g_uri_unescape_string (markup, NULL); - g_free (markup); - } - else - basename = g_strdup (title); - - header = create_header (basename); - - filename = g_filename_from_uri (uri, NULL, NULL); - - if (filename) - tooltip_text = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL); - else - tooltip_text = NULL; - - g_free (filename); - - context_menu = GTK_MENU (gtk_menu_new ()); - - this = g_object_new ( - DIRECTORY_TILE_TYPE, - "tile-uri", uri, - "nameplate-image", image, - "nameplate-header", header, - "context-menu", context_menu, - NULL); - gtk_widget_set_tooltip_text (GTK_WIDGET (this), tooltip_text); - - g_free (uri); - if (tooltip_text) - g_free (tooltip_text); - - priv = DIRECTORY_TILE_GET_PRIVATE (this); - priv->basename = g_strdup (basename); - priv->header_bin = GTK_BIN (header); - priv->icon_name = g_strdup (icon_name); - priv->mime_type = g_strdup (mime_type); - - directory_tile_private_setup (this); - - TILE (this)->actions = g_new0 (TileAction *, 6); - TILE (this)->n_actions = 6; - - menu_ctnr = GTK_CONTAINER (TILE (this)->context_menu); - - /* make open with default action */ - - markup = g_markup_printf_escaped (_("<b>Open</b>")); - action = tile_action_new (TILE (this), open_with_default_trigger, markup, TILE_ACTION_OPENS_NEW_WINDOW); - g_free (markup); - - TILE (this)->default_action = action; - - menu_item = GTK_WIDGET (GTK_WIDGET (tile_action_get_menu_item (action))); - - TILE (this)->actions [DIRECTORY_TILE_ACTION_OPEN] = action; - - gtk_container_add (menu_ctnr, menu_item); - - /* insert separator */ - - menu_item = gtk_separator_menu_item_new (); - gtk_container_add (menu_ctnr, menu_item); - - /* make rename action */ - - action = tile_action_new (TILE (this), rename_trigger, _("Rename..."), 0); - TILE (this)->actions[DIRECTORY_TILE_ACTION_RENAME] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - - /* make send to action */ - - /* Only allow Send To for local files, ideally this would use something - * equivalent to mate_vfs_uri_is_local, but that method will stat the file and - * that can hang in some conditions. */ - - if (!strncmp (TILE (this)->uri, "file://", 7)) - { - action = tile_action_new (TILE (this), send_to_trigger, _("Send To..."), - TILE_ACTION_OPENS_NEW_WINDOW); - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - } - else - { - action = NULL; - - menu_item = gtk_menu_item_new_with_label (_("Send To...")); - gtk_widget_set_sensitive (menu_item, FALSE); - } - - TILE (this)->actions[DIRECTORY_TILE_ACTION_SEND_TO] = action; - - gtk_container_add (menu_ctnr, menu_item); - - /* insert separator */ - - menu_item = gtk_separator_menu_item_new (); - gtk_container_add (menu_ctnr, menu_item); - - /* make move to trash action */ - - action = tile_action_new (TILE (this), move_to_trash_trigger, _("Move to Trash"), 0); - TILE (this)->actions[DIRECTORY_TILE_ACTION_MOVE_TO_TRASH] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - - /* make delete action */ - - if (priv->delete_enabled) - { - action = tile_action_new (TILE (this), delete_trigger, _("Delete"), 0); - TILE (this)->actions[DIRECTORY_TILE_ACTION_DELETE] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - } - - gtk_widget_show_all (GTK_WIDGET (TILE (this)->context_menu)); - - load_image (this); - - accessible = gtk_widget_get_accessible (GTK_WIDGET (this)); - if (basename) - atk_object_set_name (accessible, basename); - - g_free (basename); - - return GTK_WIDGET (this); -} - -static void -directory_tile_private_setup (DirectoryTile *tile) -{ - DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile); - MateConfClient *client; - - if (priv->mime_type) - priv->default_app = g_app_info_get_default_for_type (priv->mime_type, TRUE); - else - priv->default_app = NULL; - - priv->delete_enabled = - (gboolean) GPOINTER_TO_INT (get_mateconf_value (MATECONF_ENABLE_DELETE_KEY)); - - client = mateconf_client_get_default (); - - mateconf_client_add_dir (client, MATECONF_ENABLE_DELETE_KEY_DIR, MATECONF_CLIENT_PRELOAD_NONE, NULL); - priv->mateconf_conn_id = - connect_mateconf_notify (MATECONF_ENABLE_DELETE_KEY, mateconf_enable_delete_cb, tile); - - g_object_unref (client); -} - -static void -directory_tile_init (DirectoryTile *tile) -{ - DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile); - - priv->default_app = NULL; - priv->basename = NULL; - priv->header_bin = NULL; - priv->icon_name = NULL; - priv->mime_type = NULL; - priv->image_is_broken = TRUE; - priv->delete_enabled = FALSE; - priv->mateconf_conn_id = 0; -} - -static void -directory_tile_finalize (GObject *g_object) -{ - DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (g_object); - - MateConfClient *client; - - g_free (priv->basename); - g_free (priv->icon_name); - g_free (priv->mime_type); - - if (priv->default_app) - g_object_unref (priv->default_app); - - client = mateconf_client_get_default (); - - mateconf_client_notify_remove (client, priv->mateconf_conn_id); - mateconf_client_remove_dir (client, MATECONF_ENABLE_DELETE_KEY_DIR, NULL); - - g_object_unref (client); - - (* G_OBJECT_CLASS (directory_tile_parent_class)->finalize) (g_object); -} - -static void -directory_tile_style_set (GtkWidget *widget, GtkStyle *prev_style) -{ - load_image (DIRECTORY_TILE (widget)); -} - -static void -load_image (DirectoryTile *tile) -{ - DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile); - gchar *icon_name; - - if (priv->icon_name) - icon_name = priv->icon_name; - else - icon_name = "folder"; - - priv->image_is_broken = slab_load_image ( - GTK_IMAGE (NAMEPLATE_TILE (tile)->image), GTK_ICON_SIZE_DND, icon_name); -} - -static GtkWidget * -create_header (const gchar *name) -{ - GtkWidget *header_bin; - GtkWidget *header; - - header = gtk_label_new (name); - gtk_label_set_ellipsize (GTK_LABEL (header), PANGO_ELLIPSIZE_END); - gtk_misc_set_alignment (GTK_MISC (header), 0.0, 0.5); - - header_bin = gtk_alignment_new (0.0, 0.5, 1.0, 0.0); - gtk_container_add (GTK_CONTAINER (header_bin), header); - - g_signal_connect (G_OBJECT (header), "size-allocate", G_CALLBACK (header_size_allocate_cb), - NULL); - - return header_bin; -} - -static void -header_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer user_data) -{ - gtk_widget_set_size_request (widget, alloc->width, -1); -} - -static void -rename_entry_activate_cb (GtkEntry *entry, gpointer user_data) -{ - DirectoryTile *tile = DIRECTORY_TILE (user_data); - DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile); - - GFile *src_file; - GFile *dst_file; - - gchar *dirname; - gchar *dst_uri; - gchar *src_path; - - GtkWidget *child; - GtkWidget *header; - - gboolean res; - GError *error = NULL; - - if (strlen (gtk_entry_get_text (entry)) < 1) - return; - - src_file = g_file_new_for_uri (TILE (tile)->uri); - - src_path = g_filename_from_uri (TILE (tile)->uri, NULL, NULL); - dirname = g_path_get_dirname (src_path); - dst_uri = g_build_filename (dirname, gtk_entry_get_text (entry), NULL); - dst_file = g_file_new_for_uri (dst_uri); - - g_free (dirname); - g_free (src_path); - - res = g_file_move (src_file, dst_file, - G_FILE_COPY_NONE, NULL, NULL, NULL, &error); - - if (res) { - g_free (priv->basename); - priv->basename = g_strdup (gtk_entry_get_text (entry)); - } - else { - g_warning ("unable to move [%s] to [%s]: %s\n", TILE (tile)->uri, dst_uri, - error->message); - g_error_free (error); - } - - g_free (dst_uri); - g_object_unref (src_file); - g_object_unref (dst_file); - - header = gtk_label_new (priv->basename); - gtk_misc_set_alignment (GTK_MISC (header), 0.0, 0.5); - - child = gtk_bin_get_child (priv->header_bin); - - if (child) - gtk_widget_destroy (child); - - gtk_container_add (GTK_CONTAINER (priv->header_bin), header); - - gtk_widget_show (header); -} - -static gboolean -rename_entry_key_release_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data) -{ - return TRUE; -} - -static void -mateconf_enable_delete_cb (MateConfClient *client, guint conn_id, MateConfEntry *entry, gpointer user_data) -{ - Tile *tile = TILE (user_data); - DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (user_data); - - GtkMenuShell *menu; - gboolean delete_enabled; - - TileAction *action; - GtkWidget *menu_item; - - menu = GTK_MENU_SHELL (tile->context_menu); - - delete_enabled = mateconf_value_get_bool (entry->value); - - if (delete_enabled == priv->delete_enabled) - return; - - priv->delete_enabled = delete_enabled; - - if (priv->delete_enabled) - { - action = tile_action_new (tile, delete_trigger, _("Delete"), 0); - tile->actions[DIRECTORY_TILE_ACTION_DELETE] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_menu_shell_insert (menu, menu_item, 7); - - gtk_widget_show_all (menu_item); - } - else - { - g_object_unref (tile->actions[DIRECTORY_TILE_ACTION_DELETE]); - - tile->actions[DIRECTORY_TILE_ACTION_DELETE] = NULL; - } -} - -static void -rename_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile); - - GtkWidget *child; - GtkWidget *entry; - - - entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (entry), priv->basename); - gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); - - child = gtk_bin_get_child (priv->header_bin); - - if (child) - gtk_widget_destroy (child); - - gtk_container_add (GTK_CONTAINER (priv->header_bin), entry); - - g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (rename_entry_activate_cb), tile); - - g_signal_connect (G_OBJECT (entry), "key_release_event", - G_CALLBACK (rename_entry_key_release_cb), NULL); - - gtk_widget_show (entry); - gtk_widget_grab_focus (entry); -} - -static void -move_to_trash_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - GFile *src_file; - gboolean res; - GError *error = NULL; - - src_file = g_file_new_for_uri (TILE (tile)->uri); - - res = g_file_trash (src_file, NULL, &error); - if (!res) { - g_warning ("unable to move [%s] to the trash: %s\n", TILE (tile)->uri, - error->message); - g_error_free (error); - } - - g_object_unref (src_file); -} - -static void -delete_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - GtkDialog *confirm_dialog; - gint result; - - GFile *src_file; - gboolean res; - GError *error = NULL; - - if (GPOINTER_TO_INT (libslab_get_mateconf_value (MATECONF_CONFIRM_DELETE_KEY))) { - confirm_dialog = GTK_DIALOG(gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, - GTK_BUTTONS_NONE, _("Are you sure you want to permanently delete \"%s\"?"), DIRECTORY_TILE_GET_PRIVATE (tile)->basename)); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(confirm_dialog), _("If you delete an item, it is permanently lost.")); - - gtk_dialog_add_button (confirm_dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (confirm_dialog, GTK_STOCK_DELETE, GTK_RESPONSE_YES); - gtk_dialog_set_default_response (GTK_DIALOG (confirm_dialog), GTK_RESPONSE_YES); - - result = gtk_dialog_run (confirm_dialog); - - gtk_widget_destroy (GTK_WIDGET (confirm_dialog)); - - if (result != GTK_RESPONSE_YES) - return; - } - - src_file = g_file_new_for_uri (TILE (tile)->uri); - - res = g_file_delete (src_file, NULL, &error); - - if (!res) { - g_warning ("unable to delete [%s]: %s\n", TILE (tile)->uri, - error->message); - g_error_free (error); - } - - g_object_unref (src_file); -} - -static void -send_to_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - gchar *cmd; - gint argc; - gchar **argv_parsed = NULL; - gchar **argv = NULL; - - gchar *path; - gchar *dirname; - gchar *basename; - - GError *error = NULL; - - gint i; - - - cmd = (gchar *) get_mateconf_value (MATECONF_SEND_TO_CMD_KEY); - - if (! g_shell_parse_argv (cmd, & argc, & argv_parsed, NULL)) - goto exit; - - argv = g_new0 (gchar *, argc + 1); - - path = g_filename_from_uri (tile->uri, NULL, NULL); - dirname = g_path_get_dirname (path); - basename = g_path_get_basename (path); - - for (i = 0; i < argc; ++i) { - if (strstr (argv_parsed [i], "DIRNAME")) - argv [i] = string_replace_once (argv_parsed [i], "DIRNAME", dirname); - else if (strstr (argv_parsed [i], "BASENAME")) - argv [i] = string_replace_once (argv_parsed [i], "BASENAME", basename); - else - argv [i] = g_strdup (argv_parsed [i]); - } - - argv [argc] = NULL; - - g_free (path); - g_free (dirname); - g_free (basename); - - g_spawn_async ( - NULL, argv, NULL, G_SPAWN_SEARCH_PATH, - disown_spawned_child, NULL, NULL, & error); - - if (error) { - cmd = g_strjoinv (" ", argv); - libslab_handle_g_error ( - & error, "%s: can't execute search [%s]\n", G_STRFUNC, cmd); - g_free (cmd); - } - - g_strfreev (argv); - -exit: - - g_free (cmd); - g_strfreev (argv_parsed); -} - -static void -disown_spawned_child (gpointer user_data) -{ - setsid (); - setpgid (0, 0); -} - -static void -open_with_default_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile); - GList *uris = NULL; - gboolean res; - GdkAppLaunchContext *launch_context; - GError *error = NULL; - - if (priv->default_app) - { - uris = g_list_append (uris, TILE (tile)->uri); - - launch_context = gdk_app_launch_context_new (); - gdk_app_launch_context_set_screen (launch_context, - gtk_widget_get_screen (GTK_WIDGET (tile))); - gdk_app_launch_context_set_timestamp (launch_context, - event->time); - - res = g_app_info_launch_uris (priv->default_app, uris, - G_APP_LAUNCH_CONTEXT (launch_context), - &error); - - if (!res) { - g_warning - ("error: could not launch application with [%s]: %s\n", - TILE (tile)->uri, error->message); - g_error_free (error); - } - - g_list_free (uris); - g_object_unref (launch_context); - } else { - gchar *cmd; - cmd = string_replace_once ( - get_slab_mateconf_string (SLAB_FILE_MANAGER_OPEN_CMD), "FILE_URI", tile->uri); - spawn_process (cmd); - g_free (cmd); - } -} diff --git a/libslab/directory-tile.h b/libslab/directory-tile.h deleted file mode 100644 index 374faa2b..00000000 --- a/libslab/directory-tile.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of libtile. - * - * Copyright (c) 2006 Novell, Inc. - * - * Libtile is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Libtile 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 Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libslab; if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __DIRECTORY_TILE_H__ -#define __DIRECTORY_TILE_H__ - -#include <time.h> - -#include <libslab/nameplate-tile.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define DIRECTORY_TILE_TYPE (directory_tile_get_type ()) -#define DIRECTORY_TILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DIRECTORY_TILE_TYPE, DirectoryTile)) -#define DIRECTORY_TILE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), DIRECTORY_TILE_TYPE, DirectoryTileClass)) -#define IS_DIRECTORY_TILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DIRECTORY_TILE_TYPE)) -#define IS_DIRECTORY_TILE_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), DIRECTORY_TILE_TYPE)) -#define DIRECTORY_TILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DIRECTORY_TILE_TYPE, DirectoryTileClass)) - -typedef struct { - NameplateTile nameplate_tile; -} DirectoryTile; - -typedef struct { - NameplateTileClass nameplate_tile_class; -} DirectoryTileClass; - -#define DIRECTORY_TILE_ACTION_OPEN 0 -#define DIRECTORY_TILE_ACTION_RENAME 1 -#define DIRECTORY_TILE_ACTION_MOVE_TO_TRASH 2 -#define DIRECTORY_TILE_ACTION_DELETE 3 -#define DIRECTORY_TILE_ACTION_SEND_TO 4 - -GType directory_tile_get_type (void); - -GtkWidget *directory_tile_new (const gchar *uri, const gchar *title, const gchar *icon_name, const gchar *mime_type); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libslab/document-tile.c b/libslab/document-tile.c deleted file mode 100644 index 8b835600..00000000 --- a/libslab/document-tile.c +++ /dev/null @@ -1,1130 +0,0 @@ -/* - * This file is part of libtile. - * - * Copyright (c) 2006, 2007 Novell, Inc. - * - * Libtile is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Libtile 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 Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libslab; if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "document-tile.h" -#include "config.h" - -#include <glib/gi18n-lib.h> -#include <string.h> -#include <gio/gio.h> - -#include "slab-mate-util.h" -#include "mate-utils.h" -#include "libslab-utils.h" -#include "bookmark-agent.h" - -#define MATECONF_SEND_TO_CMD_KEY "/desktop/mate/applications/main-menu/file-area/file_send_to_cmd" -#define MATECONF_ENABLE_DELETE_KEY_DIR "/apps/caja/preferences" -#define MATECONF_ENABLE_DELETE_KEY MATECONF_ENABLE_DELETE_KEY_DIR "/enable_delete" -#define MATECONF_CONFIRM_DELETE_KEY MATECONF_ENABLE_DELETE_KEY_DIR "/confirm_trash" - -G_DEFINE_TYPE (DocumentTile, document_tile, NAMEPLATE_TILE_TYPE) - -static void document_tile_finalize (GObject *); -static void document_tile_style_set (GtkWidget *, GtkStyle *); - -static void document_tile_private_setup (DocumentTile *); -static void load_image (DocumentTile *); - -static GtkWidget *create_header (const gchar *); - -static char *create_subheader_string (time_t date); -static GtkWidget *create_subheader (const gchar *); -static void update_user_list_menu_item (DocumentTile *); - -static void header_size_allocate_cb (GtkWidget *, GtkAllocation *, gpointer); - -static void open_with_default_trigger (Tile *, TileEvent *, TileAction *); -static void open_in_file_manager_trigger (Tile *, TileEvent *, TileAction *); -static void rename_trigger (Tile *, TileEvent *, TileAction *); -static void move_to_trash_trigger (Tile *, TileEvent *, TileAction *); -static void remove_recent_item (Tile *, TileEvent *, TileAction *); -static void purge_recent_items (Tile *, TileEvent *, TileAction *); -static void delete_trigger (Tile *, TileEvent *, TileAction *); -static void user_docs_trigger (Tile *, TileEvent *, TileAction *); -static void send_to_trigger (Tile *, TileEvent *, TileAction *); - -static void rename_entry_activate_cb (GtkEntry *, gpointer); -static gboolean rename_entry_key_release_cb (GtkWidget *, GdkEventKey *, gpointer); - -static void mateconf_enable_delete_cb (MateConfClient *, guint, MateConfEntry *, gpointer); - -static void agent_notify_cb (GObject *, GParamSpec *, gpointer); - -typedef struct -{ - gchar *basename; - gchar *mime_type; - time_t modified; - - GAppInfo *default_app; - - GtkBin *header_bin; - - gboolean image_is_broken; - gchar * force_icon_name; //show an icon instead of a thumbnail - - gboolean delete_enabled; - guint mateconf_conn_id; - - BookmarkAgent *agent; - BookmarkStoreStatus store_status; - gboolean is_bookmarked; - gulong notify_signal_id; -} DocumentTilePrivate; - -#define DOCUMENT_TILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DOCUMENT_TILE_TYPE, DocumentTilePrivate)) - -static void document_tile_class_init (DocumentTileClass *this_class) -{ - GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (this_class); - - g_obj_class->finalize = document_tile_finalize; - - widget_class->style_set = document_tile_style_set; - - g_type_class_add_private (this_class, sizeof (DocumentTilePrivate)); -} - -//Use a specific icon instead of a thumbnail. -GtkWidget * -document_tile_new_force_icon (const gchar *in_uri, const gchar *mime_type, time_t modified, const gchar *icon) -{ - DocumentTile *this; - DocumentTilePrivate *priv; - - this = (DocumentTile *) document_tile_new (BOOKMARK_STORE_USER_DOCS, in_uri, mime_type, modified); - priv = DOCUMENT_TILE_GET_PRIVATE (this); - priv->force_icon_name = g_strdup (icon); - return GTK_WIDGET (this); -} - -GtkWidget * -document_tile_new (BookmarkStoreType bookmark_store_type, const gchar *in_uri, const gchar *mime_type, time_t modified) -{ - DocumentTile *this; - DocumentTilePrivate *priv; - - gchar *uri; - GtkWidget *image; - GtkWidget *header; - GtkWidget *subheader; - GtkMenu *context_menu; - - GtkContainer *menu_ctnr; - GtkWidget *menu_item; - - TileAction *action; - - gchar *basename; - - gchar *time_str; - - gchar *markup; - gchar *str; - - AtkObject *accessible; - - GFile * file; - gchar *tooltip_text; - - libslab_checkpoint ("document_tile_new(): start"); - - uri = g_strdup (in_uri); - - image = gtk_image_new (); - - markup = g_path_get_basename (uri); - basename = g_uri_unescape_string (markup, NULL); - g_free (markup); - - header = create_header (basename); - - time_str = create_subheader_string (modified); - subheader = create_subheader (time_str); - - file = g_file_new_for_uri (uri); - tooltip_text = g_file_get_parse_name (file); - g_object_unref (file); - - context_menu = GTK_MENU (gtk_menu_new ()); - - this = g_object_new (DOCUMENT_TILE_TYPE, "tile-uri", uri, "nameplate-image", image, - "nameplate-header", header, "nameplate-subheader", subheader, - "context-menu", context_menu, NULL); - gtk_widget_set_tooltip_text (GTK_WIDGET (this), tooltip_text); - - g_free (uri); - if (tooltip_text) - g_free (tooltip_text); - - priv = DOCUMENT_TILE_GET_PRIVATE (this); - priv->basename = g_strdup (basename); - priv->mime_type = g_strdup (mime_type); - priv->modified = modified; - priv->header_bin = GTK_BIN (header); - priv->agent = bookmark_agent_get_instance (bookmark_store_type); - - document_tile_private_setup (this); - TILE (this)->actions = g_new0 (TileAction *, DOCUMENT_TILE_ACTION_NUM_OF_ACTIONS); - TILE (this)->n_actions = DOCUMENT_TILE_ACTION_NUM_OF_ACTIONS; - - menu_ctnr = GTK_CONTAINER (TILE (this)->context_menu); - - /* make open with default action */ - - if (priv->default_app) { - str = g_strdup_printf (_("Open with \"%s\""), - g_app_info_get_name (priv->default_app)); - markup = g_markup_printf_escaped ("<b>%s</b>", str); - action = tile_action_new (TILE (this), open_with_default_trigger, markup, - TILE_ACTION_OPENS_NEW_WINDOW); - g_free (markup); - g_free (str); - - TILE (this)->default_action = action; - - menu_item = GTK_WIDGET (GTK_WIDGET (tile_action_get_menu_item (action))); - } - else { - action = NULL; - menu_item = gtk_menu_item_new_with_label (_("Open with Default Application")); - gtk_widget_set_sensitive (menu_item, FALSE); - } - - TILE (this)->actions[DOCUMENT_TILE_ACTION_OPEN_WITH_DEFAULT] = action; - - gtk_container_add (menu_ctnr, menu_item); - - /* make open in caja action */ - - action = tile_action_new (TILE (this), open_in_file_manager_trigger, - _("Open in File Manager"), TILE_ACTION_OPENS_NEW_WINDOW); - TILE (this)->actions[DOCUMENT_TILE_ACTION_OPEN_IN_FILE_MANAGER] = action; - - if (!TILE (this)->default_action) - TILE (this)->default_action = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - - /* insert separator */ - - menu_item = gtk_separator_menu_item_new (); - gtk_container_add (menu_ctnr, menu_item); - - /* make rename action */ - - action = tile_action_new (TILE (this), rename_trigger, _("Rename..."), 0); - TILE (this)->actions[DOCUMENT_TILE_ACTION_RENAME] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - - /* make send to action */ - - /* Only allow Send To for local files, ideally this would use something - * equivalent to mate_vfs_uri_is_local, but that method will stat the file and - * that can hang in some conditions. */ - - if (!strncmp (TILE (this)->uri, "file://", 7)) - { - action = tile_action_new (TILE (this), send_to_trigger, _("Send To..."), - TILE_ACTION_OPENS_NEW_WINDOW); - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - } - else - { - action = NULL; - - menu_item = gtk_menu_item_new_with_label (_("Send To...")); - gtk_widget_set_sensitive (menu_item, FALSE); - } - - TILE (this)->actions[DOCUMENT_TILE_ACTION_SEND_TO] = action; - - gtk_container_add (menu_ctnr, menu_item); - - /* make "add/remove to favorites" action */ - - action = tile_action_new (TILE (this), user_docs_trigger, NULL, 0); - TILE (this)->actions [DOCUMENT_TILE_ACTION_UPDATE_MAIN_MENU] = action; - - update_user_list_menu_item (this); - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - - gtk_container_add (menu_ctnr, menu_item); - - /* insert separator */ - - menu_item = gtk_separator_menu_item_new (); - gtk_container_add (menu_ctnr, menu_item); - - /* make move to trash action */ - - action = tile_action_new (TILE (this), move_to_trash_trigger, _("Move to Trash"), 0); - TILE (this)->actions[DOCUMENT_TILE_ACTION_MOVE_TO_TRASH] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - - /* make delete action */ - - if (priv->delete_enabled) - { - action = tile_action_new (TILE (this), delete_trigger, _("Delete"), 0); - TILE (this)->actions[DOCUMENT_TILE_ACTION_DELETE] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - } - - if (!priv->is_bookmarked) { - /* clean item from menu */ - action = tile_action_new (TILE (this), remove_recent_item, _("Remove from recent menu"), 0); - TILE (this)->actions[DOCUMENT_TILE_ACTION_CLEAN_ITEM] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - - /* clean all the items from menu */ - - action = tile_action_new (TILE (this), purge_recent_items, _("Purge all the recent items"), 0); - TILE (this)->actions[DOCUMENT_TILE_ACTION_CLEAN_ALL] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_container_add (menu_ctnr, menu_item); - } - - gtk_widget_show_all (GTK_WIDGET (TILE (this)->context_menu)); - - accessible = gtk_widget_get_accessible (GTK_WIDGET (this)); - if (basename) - atk_object_set_name (accessible, basename); - if (time_str) - atk_object_set_description (accessible, time_str); - - g_free (basename); - g_free (time_str); - - libslab_checkpoint ("document_tile_new(): end"); - - return GTK_WIDGET (this); -} - -static void -document_tile_private_setup (DocumentTile *this) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (this); - - GFile *file; - GAppInfo *app; - - MateConfClient *client; - GError *error = NULL; - - file = g_file_new_for_uri (TILE (this)->uri); - app = g_file_query_default_handler (file, NULL, &error); - priv->default_app = app; - - if (error) - g_error_free (error); - g_object_unref (file); - - priv->delete_enabled = - (gboolean) GPOINTER_TO_INT (get_mateconf_value (MATECONF_ENABLE_DELETE_KEY)); - - client = mateconf_client_get_default (); - - mateconf_client_add_dir (client, MATECONF_ENABLE_DELETE_KEY_DIR, MATECONF_CLIENT_PRELOAD_NONE, NULL); - priv->mateconf_conn_id = - connect_mateconf_notify (MATECONF_ENABLE_DELETE_KEY, mateconf_enable_delete_cb, this); - - g_object_unref (client); - - priv->notify_signal_id = g_signal_connect ( - G_OBJECT (priv->agent), "notify", G_CALLBACK (agent_notify_cb), this); -} - -static void -document_tile_init (DocumentTile *tile) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - - priv->basename = NULL; - priv->mime_type = NULL; - priv->modified = 0; - - priv->default_app = NULL; - - priv->header_bin = NULL; - - priv->image_is_broken = TRUE; - priv->force_icon_name = NULL; - - priv->delete_enabled = FALSE; - priv->mateconf_conn_id = 0; - - priv->agent = NULL; - priv->store_status = BOOKMARK_STORE_DEFAULT; - priv->is_bookmarked = FALSE; - priv->notify_signal_id = 0; -} - -static void -document_tile_finalize (GObject *g_object) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (g_object); - - MateConfClient *client; - - g_free (priv->basename); - g_free (priv->mime_type); - g_free (priv->force_icon_name); - - if (priv->default_app) - g_object_unref (priv->default_app); - - if (priv->notify_signal_id) - g_signal_handler_disconnect (priv->agent, priv->notify_signal_id); - - g_object_unref (G_OBJECT (priv->agent)); - - client = mateconf_client_get_default (); - - mateconf_client_notify_remove (client, priv->mateconf_conn_id); - mateconf_client_remove_dir (client, MATECONF_ENABLE_DELETE_KEY_DIR, NULL); - - g_object_unref (client); - - G_OBJECT_CLASS (document_tile_parent_class)->finalize (g_object); -} - -static void -document_tile_style_set (GtkWidget *widget, GtkStyle *prev_style) -{ - load_image (DOCUMENT_TILE (widget)); -} - -static void -load_image (DocumentTile *tile) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - - gchar *icon_id = NULL; - gboolean free_icon_id = TRUE; - MateDesktopThumbnailFactory *thumbnail_factory; - GIcon *icon; - - libslab_checkpoint ("document-tile.c: load_image(): start for %s", TILE (tile)->uri); - - if (priv->force_icon_name || ! priv->mime_type) { - if (priv->force_icon_name) - icon_id = priv->force_icon_name; - else - icon_id = "text-x-preview"; - free_icon_id = FALSE; - - goto exit; - } - - thumbnail_factory = libslab_thumbnail_factory_get (); - - icon_id = mate_desktop_thumbnail_factory_lookup (thumbnail_factory, TILE (tile)->uri, priv->modified); - - if (! icon_id) { - icon = g_content_type_get_icon (priv->mime_type); - g_object_get (icon, "name", &icon_id, NULL); - - g_object_unref (icon); - } - -exit: - - priv->image_is_broken = slab_load_image ( - GTK_IMAGE (NAMEPLATE_TILE (tile)->image), GTK_ICON_SIZE_DND, icon_id); - - if (free_icon_id && icon_id) - g_free (icon_id); - - libslab_checkpoint ("document-tile.c: load_image(): end"); -} - -/* Next function taken from e-data-server-util.c in evolution-data-server */ -/** - * e_strftime: - * @s: The string array to store the result in. - * @max: The size of array @s. - * @fmt: The formatting to use on @tm. - * @tm: The time value to format. - * - * This function is a wrapper around the strftime(3) function, which - * converts the %l and %k (12h and 24h) format variables if necessary. - * - * Returns: The number of characters placed in @s. - **/ -static size_t -e_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) -{ -#ifdef HAVE_LKSTRFTIME - return strftime(s, max, fmt, tm); -#else - char *c, *ffmt, *ff; - size_t ret; - - ffmt = g_strdup(fmt); - ff = ffmt; - while ((c = strstr(ff, "%l")) != NULL) { - c[1] = 'I'; - ff = c; - } - - ff = ffmt; - while ((c = strstr(ff, "%k")) != NULL) { - c[1] = 'H'; - ff = c; - } - -#ifdef G_OS_WIN32 - /* The Microsoft strftime() doesn't have %e either */ - ff = ffmt; - while ((c = strstr(ff, "%e")) != NULL) { - c[1] = 'd'; - ff = c; - } -#endif - - ret = strftime(s, max, ffmt, tm); - g_free(ffmt); - return ret; -#endif -} - -/* Next two functions taken from e-util.c in evolution */ -/** - * Function to do a last minute fixup of the AM/PM stuff if the locale - * and gettext haven't done it right. Most English speaking countries - * except the USA use the 24 hour clock (UK, Australia etc). However - * since they are English nobody bothers to write a language - * translation (gettext) file. So the locale turns off the AM/PM, but - * gettext does not turn on the 24 hour clock. Leaving a mess. - * - * This routine checks if AM/PM are defined in the locale, if not it - * forces the use of the 24 hour clock. - * - * The function itself is a front end on strftime and takes exactly - * the same arguments. - * - * TODO: Actually remove the '%p' from the fixed up string so that - * there isn't a stray space. - **/ - -static size_t -e_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm) -{ - char buf[10]; - char *sp; - char *ffmt; - size_t ret; - - if (strstr(fmt, "%p")==NULL && strstr(fmt, "%P")==NULL) { - /* No AM/PM involved - can use the fmt string directly */ - ret=e_strftime(s, max, fmt, tm); - } else { - /* Get the AM/PM symbol from the locale */ - e_strftime (buf, 10, "%p", tm); - - if (buf[0]) { - /** - * AM/PM have been defined in the locale - * so we can use the fmt string directly - **/ - ret=e_strftime(s, max, fmt, tm); - } else { - /** - * No AM/PM defined by locale - * must change to 24 hour clock - **/ - ffmt=g_strdup(fmt); - for (sp=ffmt; (sp=strstr(sp, "%l")); sp++) { - /** - * Maybe this should be 'k', but I have never - * seen a 24 clock actually use that format - **/ - sp[1]='H'; - } - for (sp=ffmt; (sp=strstr(sp, "%I")); sp++) { - sp[1]='H'; - } - ret=e_strftime(s, max, ffmt, tm); - g_free(ffmt); - } - } - - return(ret); -} - -static size_t -e_utf8_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm) -{ - size_t sz, ret; - char *locale_fmt, *buf; - - locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL); - if (!locale_fmt) - return 0; - - ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm); - if (!ret) { - g_free (locale_fmt); - return 0; - } - - buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL); - if (!buf) { - g_free (locale_fmt); - return 0; - } - - if (sz >= max) { - char *tmp = buf + max - 1; - tmp = g_utf8_find_prev_char(buf, tmp); - if (tmp) - sz = tmp - buf; - else - sz = 0; - } - memcpy(s, buf, sz); - s[sz] = '\0'; - g_free(locale_fmt); - g_free(buf); - return sz; -} - -static char * -create_subheader_string (time_t date) -{ - time_t nowdate = time(NULL); - time_t yesdate; - struct tm then, now, yesterday; - char buf[100]; - gboolean done = FALSE; - - if (date == 0) { - return g_strdup (_("?")); - } - - localtime_r (&date, &then); - localtime_r (&nowdate, &now); - - if (nowdate - date < 60 * 60 * 8 && nowdate > date) { - e_utf8_strftime_fix_am_pm (buf, 100, _("%l:%M %p"), &then); - done = TRUE; - } - - if (!done) { - if (then.tm_mday == now.tm_mday && - then.tm_mon == now.tm_mon && - then.tm_year == now.tm_year) { - e_utf8_strftime_fix_am_pm (buf, 100, _("Today %l:%M %p"), &then); - done = TRUE; - } - } - if (!done) { - yesdate = nowdate - 60 * 60 * 24; - localtime_r (&yesdate, &yesterday); - if (then.tm_mday == yesterday.tm_mday && - then.tm_mon == yesterday.tm_mon && - then.tm_year == yesterday.tm_year) { - e_utf8_strftime_fix_am_pm (buf, 100, _("Yesterday %l:%M %p"), &then); - done = TRUE; - } - } - if (!done) { - int i; - for (i = 2; i < 7; i++) { - yesdate = nowdate - 60 * 60 * 24 * i; - localtime_r (&yesdate, &yesterday); - if (then.tm_mday == yesterday.tm_mday && - then.tm_mon == yesterday.tm_mon && - then.tm_year == yesterday.tm_year) { - e_utf8_strftime_fix_am_pm (buf, 100, _("%a %l:%M %p"), &then); - done = TRUE; - break; - } - } - } - if (!done) { - if (then.tm_year == now.tm_year) { - e_utf8_strftime_fix_am_pm (buf, 100, _("%b %d %l:%M %p"), &then); - } else { - e_utf8_strftime_fix_am_pm (buf, 100, _("%b %d %Y"), &then); - } - } - - return g_strdup (g_strstrip (buf)); -} - -static GtkWidget * -create_header (const gchar *name) -{ - GtkWidget *header_bin; - GtkWidget *header; - - header = gtk_label_new (name); - gtk_label_set_ellipsize (GTK_LABEL (header), PANGO_ELLIPSIZE_END); - gtk_misc_set_alignment (GTK_MISC (header), 0.0, 0.5); - - header_bin = gtk_alignment_new (0.0, 0.5, 1.0, 0.0); - gtk_container_add (GTK_CONTAINER (header_bin), header); - - g_signal_connect (G_OBJECT (header), "size-allocate", G_CALLBACK (header_size_allocate_cb), - NULL); - - return header_bin; -} - -static GtkWidget * -create_subheader (const gchar *desc) -{ - GtkWidget *subheader; - - subheader = gtk_label_new (desc); - gtk_label_set_ellipsize (GTK_LABEL (subheader), PANGO_ELLIPSIZE_END); - gtk_misc_set_alignment (GTK_MISC (subheader), 0.0, 0.5); - gtk_widget_modify_fg (subheader, GTK_STATE_NORMAL, - &subheader->style->fg[GTK_STATE_INSENSITIVE]); - - return subheader; -} - -static void -update_user_list_menu_item (DocumentTile *this) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (this); - - TileAction *action; - GtkMenuItem *item; - - - action = TILE (this)->actions [DOCUMENT_TILE_ACTION_UPDATE_MAIN_MENU]; - - if (! action) - return; - - priv->is_bookmarked = bookmark_agent_has_item (bookmark_agent_get_instance (BOOKMARK_STORE_USER_DOCS), TILE (this)->uri); - - if (priv->is_bookmarked) - tile_action_set_menu_item_label (action, _("Remove from Favorites")); - else - tile_action_set_menu_item_label (action, _("Add to Favorites")); - - item = tile_action_get_menu_item (action); - - if (! GTK_IS_MENU_ITEM (item)) - return; - - g_object_get (G_OBJECT (priv->agent), BOOKMARK_AGENT_STORE_STATUS_PROP, & priv->store_status, NULL); - - gtk_widget_set_sensitive (GTK_WIDGET (item), (priv->store_status != BOOKMARK_STORE_DEFAULT_ONLY)); -} - -static void -header_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer user_data) -{ - gtk_widget_set_size_request (widget, alloc->width, -1); -} - -static void -rename_entry_activate_cb (GtkEntry *entry, gpointer user_data) -{ - DocumentTile *tile = DOCUMENT_TILE (user_data); - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - - GFile *src_file; - GFile *dst_file; - - char *src_path; - char *dirname; - char *dst_path; - - gboolean res; - GError *error = NULL; - - GtkWidget *child; - GtkWidget *header; - - if (strlen (gtk_entry_get_text (entry)) < 1) - return; - - src_file = g_file_new_for_uri (TILE (tile)->uri); - - src_path = g_filename_from_uri (TILE (tile)->uri, NULL, NULL); - dirname = g_path_get_dirname (src_path); - dst_path = g_build_filename (dirname, gtk_entry_get_text (entry), NULL); - dst_file = g_file_new_for_path (dst_path); - - res = g_file_move (src_file, dst_file, 0, NULL, NULL, NULL, &error); - - if (res) { - char *dst_uri; - - dst_uri = g_file_get_uri (dst_file); - bookmark_agent_move_item (priv->agent, TILE (tile)->uri, dst_uri); - g_free (dst_uri); - - g_free (priv->basename); - priv->basename = g_strdup (gtk_entry_get_text (entry)); - } - else { - g_warning ("unable to move [%s] to [%s]: %s\n", TILE (tile)->uri, - dst_path, error->message); - g_error_free (error); - } - - header = gtk_label_new (priv->basename); - gtk_misc_set_alignment (GTK_MISC (header), 0.0, 0.5); - - child = gtk_bin_get_child (priv->header_bin); - - if (child) - gtk_widget_destroy (child); - - gtk_container_add (GTK_CONTAINER (priv->header_bin), header); - - gtk_widget_show (header); - - g_object_unref (src_file); - g_object_unref (dst_file); - - g_free (dirname); - g_free (dst_path); - g_free (src_path); -} - -static gboolean -rename_entry_key_release_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data) -{ - return TRUE; -} - -static void -mateconf_enable_delete_cb (MateConfClient *client, guint conn_id, MateConfEntry *entry, gpointer user_data) -{ - Tile *tile = TILE (user_data); - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (user_data); - - GtkMenuShell *menu; - gboolean delete_enabled; - - TileAction *action; - GtkWidget *menu_item; - - menu = GTK_MENU_SHELL (tile->context_menu); - - delete_enabled = mateconf_value_get_bool (entry->value); - - if (delete_enabled == priv->delete_enabled) - return; - - priv->delete_enabled = delete_enabled; - - if (priv->delete_enabled) - { - action = tile_action_new (tile, delete_trigger, _("Delete"), 0); - tile->actions[DOCUMENT_TILE_ACTION_DELETE] = action; - - menu_item = GTK_WIDGET (tile_action_get_menu_item (action)); - gtk_menu_shell_insert (menu, menu_item, 7); - - gtk_widget_show_all (menu_item); - } - else - { - g_object_unref (tile->actions[DOCUMENT_TILE_ACTION_DELETE]); - - tile->actions[DOCUMENT_TILE_ACTION_DELETE] = NULL; - } -} - -static void -open_with_default_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - - GList *uris = NULL; - gboolean res; - GdkAppLaunchContext *launch_context; - GError *error = NULL; - - if (priv->default_app) - { - uris = g_list_append (uris, TILE (tile)->uri); - launch_context = gdk_app_launch_context_new (); - gdk_app_launch_context_set_screen (launch_context, - gtk_widget_get_screen (GTK_WIDGET (tile))); - gdk_app_launch_context_set_timestamp (launch_context, - event->time); - - res = g_app_info_launch_uris (priv->default_app, uris, - G_APP_LAUNCH_CONTEXT (launch_context), &error); - - if (!res) { - g_warning - ("error: could not launch application with [%s]: %s\n", - TILE (tile)->uri, error->message); - g_error_free (error); - } - - g_list_free (uris); - g_object_unref (launch_context); - } -} - -static void -open_in_file_manager_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - GFile *filename; - GFile *dirname; - gchar *uri; - - gchar *cmd; - - filename = g_file_new_for_uri (TILE (tile)->uri); - dirname = g_file_get_parent (filename); - uri = g_file_get_uri (dirname); - - if (!uri) - g_warning ("error getting dirname for [%s]\n", TILE (tile)->uri); - else - { - cmd = string_replace_once (get_slab_mateconf_string (SLAB_FILE_MANAGER_OPEN_CMD), - "FILE_URI", uri); - spawn_process (cmd); - - g_free (cmd); - } - - g_object_unref (filename); - g_object_unref (dirname); - g_free (uri); -} - -static void -rename_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - - GtkWidget *child; - GtkWidget *entry; - - - entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (entry), priv->basename); - gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); - - child = gtk_bin_get_child (priv->header_bin); - - if (child) - gtk_widget_destroy (child); - - gtk_container_add (GTK_CONTAINER (priv->header_bin), entry); - - g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (rename_entry_activate_cb), tile); - - g_signal_connect (G_OBJECT (entry), "key_release_event", - G_CALLBACK (rename_entry_key_release_cb), NULL); - - gtk_widget_show (entry); - gtk_widget_grab_focus (entry); -} - -static void -remove_recent_item (Tile *tile, TileEvent *event, TileAction *action) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - bookmark_agent_remove_item (priv->agent, TILE (tile)->uri); -} - -static void -purge_recent_items (Tile *tile, TileEvent *event, TileAction *action) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - bookmark_agent_purge_items (priv->agent); -} - -static void -move_to_trash_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - - GFile *src_file; - gboolean res; - GError *error = NULL; - - src_file = g_file_new_for_uri (TILE (tile)->uri); - - res = g_file_trash (src_file, NULL, &error); - - if (res) - bookmark_agent_remove_item (priv->agent, TILE (tile)->uri); - else { - g_warning ("unable to move [%s] to the trash: %s\n", TILE (tile)->uri, - error->message); - - g_error_free (error); - } - - g_object_unref (src_file); -} - -static void -delete_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (tile); - - GtkDialog *confirm_dialog; - gint result; - - GFile *src_file; - gboolean res; - GError *error = NULL; - - - if (GPOINTER_TO_INT (libslab_get_mateconf_value (MATECONF_CONFIRM_DELETE_KEY))) { - confirm_dialog = GTK_DIALOG(gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, - GTK_BUTTONS_NONE, _("Are you sure you want to permanently delete \"%s\"?"), priv->basename)); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(confirm_dialog), _("If you delete an item, it is permanently lost.")); - - gtk_dialog_add_button (confirm_dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (confirm_dialog, GTK_STOCK_DELETE, GTK_RESPONSE_YES); - gtk_dialog_set_default_response (GTK_DIALOG (confirm_dialog), GTK_RESPONSE_YES); - - result = gtk_dialog_run (confirm_dialog); - - gtk_widget_destroy (GTK_WIDGET (confirm_dialog)); - - if (result != GTK_RESPONSE_YES) - return; - } - - src_file = g_file_new_for_uri (TILE (tile)->uri); - - res = g_file_delete (src_file, NULL, &error); - - if (res) - bookmark_agent_remove_item (priv->agent, TILE (tile)->uri); - else { - g_warning ("unable to delete [%s]: %s\n", TILE (tile)->uri, - error->message); - g_error_free (error); - } - - g_object_unref (src_file); -} - -static void -user_docs_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - DocumentTile *this = DOCUMENT_TILE (tile); - DocumentTilePrivate *priv = DOCUMENT_TILE_GET_PRIVATE (this); - - BookmarkItem *item; - - - if (priv->is_bookmarked) - bookmark_agent_remove_item (priv->agent, tile->uri); - else { - item = g_new0 (BookmarkItem, 1); - item->uri = tile->uri; - item->mime_type = priv->mime_type; - item->mtime = priv->modified; - if (priv->default_app) { - item->app_name = (gchar *) g_app_info_get_name (priv->default_app); - item->app_exec = (gchar *) g_app_info_get_executable (priv->default_app); - } - - bookmark_agent_add_item (priv->agent, item); - g_free (item); - } - - update_user_list_menu_item (this); -} - -static void -send_to_trigger (Tile *tile, TileEvent *event, TileAction *action) -{ - gchar *cmd; - gchar **argv; - - gchar *filename; - gchar *dirname; - gchar *basename; - - GError *error = NULL; - - gchar *tmp; - gint i; - - cmd = (gchar *) get_mateconf_value (MATECONF_SEND_TO_CMD_KEY); - argv = g_strsplit (cmd, " ", 0); - - filename = g_filename_from_uri (TILE (tile)->uri, NULL, NULL); - dirname = g_path_get_dirname (filename); - basename = g_path_get_basename (filename); - - for (i = 0; argv[i]; ++i) - { - if (strstr (argv[i], "DIRNAME")) - { - tmp = string_replace_once (argv[i], "DIRNAME", dirname); - g_free (argv[i]); - argv[i] = tmp; - } - - if (strstr (argv[i], "BASENAME")) - { - tmp = string_replace_once (argv[i], "BASENAME", basename); - g_free (argv[i]); - argv[i] = tmp; - } - } - - gdk_spawn_on_screen (gtk_widget_get_screen (GTK_WIDGET (tile)), NULL, argv, NULL, - G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error); - - if (error) - handle_g_error (&error, "error in %s", G_STRFUNC); - - g_free (cmd); - g_free (filename); - g_free (dirname); - g_free (basename); - g_strfreev (argv); -} - -static void -agent_notify_cb (GObject *g_obj, GParamSpec *pspec, gpointer user_data) -{ - update_user_list_menu_item (DOCUMENT_TILE (user_data)); -} diff --git a/libslab/document-tile.h b/libslab/document-tile.h deleted file mode 100644 index c5f1f1f8..00000000 --- a/libslab/document-tile.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of libtile. - * - * Copyright (c) 2006 Novell, Inc. - * - * Libtile is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Libtile 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 Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libslab; if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __DOCUMENT_TILE_H__ -#define __DOCUMENT_TILE_H__ - -#include <time.h> - -#include "nameplate-tile.h" -#include "bookmark-agent.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define DOCUMENT_TILE_TYPE (document_tile_get_type ()) -#define DOCUMENT_TILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DOCUMENT_TILE_TYPE, DocumentTile)) -#define DOCUMENT_TILE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), DOCUMENT_TILE_TYPE, DocumentTileClass)) -#define IS_DOCUMENT_TILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DOCUMENT_TILE_TYPE)) -#define IS_DOCUMENT_TILE_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), DOCUMENT_TILE_TYPE)) -#define DOCUMENT_TILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DOCUMENT_TILE_TYPE, DocumentTileClass)) - -typedef struct { - NameplateTile nameplate_tile; -} DocumentTile; - -typedef struct { - NameplateTileClass nameplate_tile_class; -} DocumentTileClass; - -#define DOCUMENT_TILE_ACTION_OPEN_WITH_DEFAULT 0 -#define DOCUMENT_TILE_ACTION_OPEN_IN_FILE_MANAGER 1 -#define DOCUMENT_TILE_ACTION_RENAME 2 -#define DOCUMENT_TILE_ACTION_MOVE_TO_TRASH 3 -#define DOCUMENT_TILE_ACTION_DELETE 4 -#define DOCUMENT_TILE_ACTION_UPDATE_MAIN_MENU 5 -#define DOCUMENT_TILE_ACTION_SEND_TO 6 -#define DOCUMENT_TILE_ACTION_CLEAN_ITEM 7 -#define DOCUMENT_TILE_ACTION_CLEAN_ALL 8 -#define DOCUMENT_TILE_ACTION_NUM_OF_ACTIONS 9 /* must be last entry and equal to the number of actions */ - -GType document_tile_get_type (void); - -GtkWidget *document_tile_new (BookmarkStoreType bookmark_store_type, const gchar *uri, const gchar *mime_type, time_t modified); - -//If you want to show a icon instead of a thumbnail -GtkWidget *document_tile_new_force_icon (const gchar *uri, const gchar *mime_type, time_t modified, const gchar *icon); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libslab/libslab-utils.c b/libslab/libslab-utils.c index 80bf6472..fa96b260 100644 --- a/libslab/libslab-utils.c +++ b/libslab/libslab-utils.c @@ -11,7 +11,6 @@ #include <sys/stat.h> #include <sys/resource.h> #include <sys/time.h> -#include <mateconf/mateconf-value.h> #include <gtk/gtk.h> #define DESKTOP_ITEM_TERMINAL_EMULATOR_FLAG "TerminalEmulator" @@ -273,201 +272,6 @@ libslab_strlen (const gchar *a) return strlen (a); } -gpointer -libslab_get_mateconf_value (const gchar *key) -{ - MateConfClient *client; - MateConfValue *value; - GError *error = NULL; - - gpointer retval = NULL; - - GList *list; - GSList *slist; - - MateConfValue *value_i; - GSList *node; - - - client = mateconf_client_get_default (); - value = mateconf_client_get (client, key, & error); - - if (error || ! value) - libslab_handle_g_error (& error, "%s: error getting %s", G_STRFUNC, key); - else { - switch (value->type) { - case MATECONF_VALUE_STRING: - retval = (gpointer) g_strdup (mateconf_value_get_string (value)); - break; - - case MATECONF_VALUE_INT: - retval = GINT_TO_POINTER (mateconf_value_get_int (value)); - break; - - case MATECONF_VALUE_BOOL: - retval = GINT_TO_POINTER (mateconf_value_get_bool (value)); - break; - - case MATECONF_VALUE_LIST: - list = NULL; - slist = mateconf_value_get_list (value); - - for (node = slist; node; node = node->next) { - value_i = (MateConfValue *) node->data; - - if (value_i->type == MATECONF_VALUE_STRING) - list = g_list_append ( - list, g_strdup ( - mateconf_value_get_string (value_i))); - else if (value_i->type == MATECONF_VALUE_INT) - list = g_list_append ( - list, GINT_TO_POINTER ( - mateconf_value_get_int (value_i))); - else - ; - } - - retval = (gpointer) list; - - break; - - default: - break; - } - } - - g_object_unref (client); - - if (value) - mateconf_value_free (value); - - return retval; -} - -void -libslab_set_mateconf_value (const gchar *key, gconstpointer data) -{ - MateConfClient *client; - MateConfValue *value; - - MateConfValueType type; - MateConfValueType list_type; - - GSList *slist = NULL; - - GError *error = NULL; - - MateConfValue *value_i; - GList *node; - - - client = mateconf_client_get_default (); - value = mateconf_client_get (client, key, & error); - - if (error) { - libslab_handle_g_error (&error, "%s: error getting %s", G_STRFUNC, key); - - goto exit; - } - - type = value->type; - list_type = ((type == MATECONF_VALUE_LIST) ? - mateconf_value_get_list_type (value) : MATECONF_VALUE_INVALID); - - mateconf_value_free (value); - value = mateconf_value_new (type); - - if (type == MATECONF_VALUE_LIST) - mateconf_value_set_list_type (value, list_type); - - switch (type) { - case MATECONF_VALUE_STRING: - mateconf_value_set_string (value, g_strdup ((gchar *) data)); - break; - - case MATECONF_VALUE_INT: - mateconf_value_set_int (value, GPOINTER_TO_INT (data)); - break; - - case MATECONF_VALUE_BOOL: - mateconf_value_set_bool (value, GPOINTER_TO_INT (data)); - break; - - case MATECONF_VALUE_LIST: - for (node = (GList *) data; node; node = node->next) { - value_i = mateconf_value_new (list_type); - - if (list_type == MATECONF_VALUE_STRING) - mateconf_value_set_string (value_i, (const gchar *) node->data); - else if (list_type == MATECONF_VALUE_INT) - mateconf_value_set_int (value_i, GPOINTER_TO_INT (node->data)); - else - g_assert_not_reached (); - - slist = g_slist_append (slist, value_i); - } - - mateconf_value_set_list_nocopy (value, slist); - - break; - - default: - break; - } - - mateconf_client_set (client, key, value, & error); - - if (error) - libslab_handle_g_error (&error, "%s: error setting %s", G_STRFUNC, key); - -exit: - - mateconf_value_free (value); - g_object_unref (client); -} - -guint -libslab_mateconf_notify_add (const gchar *key, MateConfClientNotifyFunc callback, gpointer user_data) -{ - MateConfClient *client; - guint conn_id; - - GError *error = NULL; - - - client = mateconf_client_get_default (); - conn_id = mateconf_client_notify_add (client, key, callback, user_data, NULL, & error); - - if (error) - libslab_handle_g_error ( - & error, "%s: error adding mateconf notify for (%s)", G_STRFUNC, key); - - g_object_unref (client); - - return conn_id; -} - -void -libslab_mateconf_notify_remove (guint conn_id) -{ - MateConfClient *client; - - GError *error = NULL; - - - if (conn_id == 0) - return; - - client = mateconf_client_get_default (); - mateconf_client_notify_remove (client, conn_id); - - if (error) - libslab_handle_g_error ( - & error, "%s: error removing mateconf notify", G_STRFUNC); - - g_object_unref (client); -} - void libslab_handle_g_error (GError **error, const gchar *msg_format, ...) { diff --git a/libslab/libslab-utils.h b/libslab/libslab-utils.h index 10bf61b3..507de7b4 100644 --- a/libslab/libslab-utils.h +++ b/libslab/libslab-utils.h @@ -3,7 +3,6 @@ #include <glib.h> #include <gtk/gtk.h> -#include <mateconf/mateconf-client.h> #include <libmate/mate-desktop-item.h> #define MATE_DESKTOP_USE_UNSTABLE_API 1 #include <libmateui/mate-desktop-thumbnail.h> @@ -20,10 +19,6 @@ gboolean libslab_mate_desktop_item_open_help (MateDesktopItem *item); guint32 libslab_get_current_time_millis (void); gint libslab_strcmp (const gchar *a, const gchar *b); gint libslab_strlen (const gchar *a); -gpointer libslab_get_mateconf_value (const gchar *key); -void libslab_set_mateconf_value (const gchar *key, gconstpointer data); -guint libslab_mateconf_notify_add (const gchar *key, MateConfClientNotifyFunc callback, gpointer user_data); -void libslab_mateconf_notify_remove (guint conn_id); void libslab_handle_g_error (GError **error, const gchar *msg_format, ...); gboolean libslab_desktop_item_is_a_terminal (const gchar *uri); gboolean libslab_desktop_item_is_logout (const gchar *uri); diff --git a/libslab/mate-utils.c b/libslab/mate-utils.c index 11bcfdce..f3c31c42 100644 --- a/libslab/mate-utils.c +++ b/libslab/mate-utils.c @@ -109,186 +109,6 @@ load_desktop_item_by_unknown_id (const gchar * id) return NULL; } -gpointer -get_mateconf_value (const gchar * key) -{ - MateConfClient *client; - MateConfValue *value; - GError *error = NULL; - - gpointer retval = NULL; - - GList *list; - GSList *slist; - - MateConfValue *value_i; - GSList *node; - - client = mateconf_client_get_default (); - value = mateconf_client_get (client, key, &error); - - if (error || ! value) - { - handle_g_error (&error, "%s: error getting %s", G_STRFUNC, key); - - goto exit; - } - - switch (value->type) - { - case MATECONF_VALUE_STRING: - retval = (gpointer) g_strdup (mateconf_value_get_string (value)); - break; - - case MATECONF_VALUE_INT: - retval = GINT_TO_POINTER (mateconf_value_get_int (value)); - break; - - case MATECONF_VALUE_BOOL: - retval = GINT_TO_POINTER (mateconf_value_get_bool (value)); - break; - - case MATECONF_VALUE_LIST: - list = NULL; - slist = mateconf_value_get_list (value); - - for (node = slist; node; node = node->next) - { - value_i = (MateConfValue *) node->data; - - if (value_i->type == MATECONF_VALUE_STRING) - list = g_list_append (list, - g_strdup (mateconf_value_get_string (value_i))); - else if (value_i->type == MATECONF_VALUE_INT) - list = g_list_append (list, - GINT_TO_POINTER (mateconf_value_get_int (value_i))); - else - g_assert_not_reached (); - } - - retval = (gpointer) list; - - break; - - default: - g_assert_not_reached (); - break; - } - - exit: - - g_object_unref (client); - if(value) - mateconf_value_free (value); - - return retval; -} - -void -set_mateconf_value (const gchar * key, gconstpointer data) -{ - MateConfClient *client; - MateConfValue *value; - - MateConfValueType type; - MateConfValueType list_type; - - GSList *slist = NULL; - - GError *error = NULL; - - MateConfValue *value_i; - GList *node; - - client = mateconf_client_get_default (); - value = mateconf_client_get (client, key, &error); - - if (error) - { - handle_g_error (&error, "%s: error getting %s", G_STRFUNC, key); - - goto exit; - } - - type = value->type; - list_type = - (type == - MATECONF_VALUE_LIST ? mateconf_value_get_list_type (value) : MATECONF_VALUE_INVALID); - - mateconf_value_free (value); - value = mateconf_value_new (type); - - if (type == MATECONF_VALUE_LIST) - mateconf_value_set_list_type (value, list_type); - - switch (type) - { - case MATECONF_VALUE_STRING: - mateconf_value_set_string (value, g_strdup ((gchar *) data)); - break; - - case MATECONF_VALUE_INT: - mateconf_value_set_int (value, GPOINTER_TO_INT (data)); - break; - - case MATECONF_VALUE_BOOL: - mateconf_value_set_bool (value, GPOINTER_TO_INT (data)); - break; - - case MATECONF_VALUE_LIST: - for (node = (GList *) data; node; node = node->next) - { - value_i = mateconf_value_new (list_type); - - if (list_type == MATECONF_VALUE_STRING) - mateconf_value_set_string (value_i, (const gchar *) node->data); - else if (list_type == MATECONF_VALUE_INT) - mateconf_value_set_int (value_i, GPOINTER_TO_INT (node->data)); - else - g_assert_not_reached (); - - slist = g_slist_append (slist, value_i); - } - - mateconf_value_set_list_nocopy (value, slist); - - break; - - default: - g_assert_not_reached (); - break; - } - - mateconf_client_set (client, key, value, &error); - - if (error) - handle_g_error (&error, "%s: error setting %s", G_STRFUNC, key); - - exit: - - mateconf_value_free (value); - g_object_unref (client); -} - -guint -connect_mateconf_notify (const gchar * key, MateConfClientNotifyFunc cb, gpointer user_data) -{ - MateConfClient *client; - guint conn_id; - - GError *error = NULL; - - client = mateconf_client_get_default (); - conn_id = mateconf_client_notify_add (client, key, cb, user_data, NULL, &error); - - if (error) - handle_g_error (&error, "%s: error adding notify for (%s)", G_STRFUNC, key); - - g_object_unref (client); - - return conn_id; -} - void handle_g_error (GError ** error, const gchar * msg_format, ...) { diff --git a/libslab/mate-utils.h b/libslab/mate-utils.h index fcc7e586..294e20ec 100644 --- a/libslab/mate-utils.h +++ b/libslab/mate-utils.h @@ -22,7 +22,6 @@ #define __MATE_UTILS_H__ #include <gtk/gtk.h> -#include <mateconf/mateconf-client.h> #include <libmate/mate-desktop-item.h> #ifdef __cplusplus @@ -32,9 +31,6 @@ extern "C" { gboolean load_image_by_id (GtkImage * image, GtkIconSize size, const gchar * image_id); MateDesktopItem *load_desktop_item_by_unknown_id (const gchar * id); -gpointer get_mateconf_value (const gchar * key); -void set_mateconf_value (const gchar * key, gconstpointer data); -guint connect_mateconf_notify (const gchar * key, MateConfClientNotifyFunc cb, gpointer user_data); void handle_g_error (GError ** error, const gchar * user_format, ...); GtkWidget *get_main_menu_section_header (const gchar * markup); diff --git a/libslab/slab-mate-util.c b/libslab/slab-mate-util.c index 4ca71e3f..31088346 100644 --- a/libslab/slab-mate-util.c +++ b/libslab/slab-mate-util.c @@ -21,80 +21,9 @@ #include "slab-mate-util.h" #include "libslab-utils.h" -#include <mateconf/mateconf-client.h> #include <gio/gio.h> #include <string.h> -gboolean -get_slab_mateconf_bool (const gchar * key) -{ - MateConfClient *mateconf_client; - GError *error; - - gboolean value; - - mateconf_client = mateconf_client_get_default (); - error = NULL; - - value = mateconf_client_get_bool (mateconf_client, key, &error); - - g_object_unref (mateconf_client); - - if (error) - { - g_warning ("error accessing %s [%s]\n", key, error->message); - g_error_free (error); - } - - return value; -} - -gint -get_slab_mateconf_int (const gchar * key) -{ - MateConfClient *mateconf_client; - GError *error; - - gint value; - - mateconf_client = mateconf_client_get_default (); - error = NULL; - - value = mateconf_client_get_int (mateconf_client, key, &error); - - g_object_unref (mateconf_client); - if (error) - { - g_warning ("error accessing %s [%s]\n", key, error->message); - g_error_free (error); - } - - return value; -} - -gchar * -get_slab_mateconf_string (const gchar * key) -{ - MateConfClient *mateconf_client; - GError *error; - - gchar *value; - - mateconf_client = mateconf_client_get_default (); - error = NULL; - - value = mateconf_client_get_string (mateconf_client, key, &error); - - g_object_unref (mateconf_client); - if (error) - { - g_warning ("error accessing %s [%s]\n", key, error->message); - g_error_free (error); - } - - return value; -} - void free_list_of_strings (GList * string_list) { @@ -103,52 +32,6 @@ free_list_of_strings (GList * string_list) g_list_free (string_list); } -void -free_slab_mateconf_slist_of_strings (GSList * string_list) -{ - g_assert (string_list != NULL); - g_slist_foreach (string_list, (GFunc) g_free, NULL); - g_slist_free (string_list); -} - -GSList * -get_slab_mateconf_slist (const gchar * key) -{ - MateConfClient *mateconf_client; - GError *error; - - GSList *value; - - mateconf_client = mateconf_client_get_default (); - error = NULL; - - value = mateconf_client_get_list (mateconf_client, key, MATECONF_VALUE_STRING, &error); - - g_object_unref (mateconf_client); - if (error) - { - g_warning ("error accessing %s [%s]\n", key, error->message); - - g_error_free (error); - } - - return value; -} - -MateDesktopItem * -load_desktop_item_from_mateconf_key (const gchar * key) -{ - MateDesktopItem *item; - gchar *id = get_slab_mateconf_string (key); - - if (!id) - return NULL; - - item = load_desktop_item_from_unknown (id); - g_free (id); - return item; -} - MateDesktopItem * load_desktop_item_from_unknown (const gchar *id) { @@ -293,47 +176,6 @@ open_desktop_item_help (MateDesktopItem * desktop_item) return TRUE; } -gboolean -desktop_item_is_in_main_menu (MateDesktopItem * desktop_item) -{ - return desktop_uri_is_in_main_menu (mate_desktop_item_get_location (desktop_item)); -} - -gboolean -desktop_uri_is_in_main_menu (const gchar * uri) -{ - GSList *app_list; - - GSList *node; - gint offset; - gint uri_len; - gboolean found = FALSE; - - app_list = get_slab_mateconf_slist (SLAB_USER_SPECIFIED_APPS_KEY); - - if (!app_list) - return FALSE; - - uri_len = strlen (uri); - - for (node = app_list; node; node = node->next) - { - offset = uri_len - strlen ((gchar *) node->data); - - if (offset < 0) - offset = 0; - - if (!strcmp (&uri[offset], (gchar *) node->data)) - { - found = TRUE; - break; - } - } - - free_slab_mateconf_slist_of_strings (app_list); - return found; -} - gint desktop_item_location_compare (gconstpointer a_obj, gconstpointer b_obj) { diff --git a/libslab/slab-mate-util.h b/libslab/slab-mate-util.h index d988f48b..b3dcb506 100644 --- a/libslab/slab-mate-util.h +++ b/libslab/slab-mate-util.h @@ -47,14 +47,8 @@ extern "C" { #define SLAB_FILE_MANAGER_OPEN_CMD "/desktop/mate/applications/main-menu/file-area/file_mgr_open_cmd" #define SLAB_FILE_SEND_TO_CMD "/desktop/mate/applications/main-menu/file-area/file_send_to_cmd" -gboolean get_slab_mateconf_bool (const gchar * key); -gint get_slab_mateconf_int (const gchar * key); -GSList *get_slab_mateconf_slist (const gchar * key); -void free_slab_mateconf_slist_of_strings (GSList * list); void free_list_of_strings (GList * list); -gchar *get_slab_mateconf_string (const gchar * key); -MateDesktopItem *load_desktop_item_from_mateconf_key (const gchar * key); MateDesktopItem *load_desktop_item_from_unknown (const gchar * id); gchar *get_package_name_from_desktop_item (MateDesktopItem * desktop_item); @@ -62,9 +56,6 @@ gchar *get_package_name_from_desktop_item (MateDesktopItem * desktop_item); gboolean open_desktop_item_exec (MateDesktopItem * desktop_item); gboolean open_desktop_item_help (MateDesktopItem * desktop_item); -gboolean desktop_item_is_in_main_menu (MateDesktopItem * desktop_item); -gboolean desktop_uri_is_in_main_menu (const gchar * uri); - gint desktop_item_location_compare (gconstpointer a, gconstpointer b); gboolean slab_load_image (GtkImage * image, GtkIconSize size, const gchar * image_id); diff --git a/libslab/slab.h b/libslab/slab.h index cacf7a9c..0cfb363c 100644 --- a/libslab/slab.h +++ b/libslab/slab.h @@ -26,8 +26,6 @@ #include <libslab/app-shell.h> #include <libslab/application-tile.h> #include <libslab/bookmark-agent.h> -#include <libslab/directory-tile.h> -#include <libslab/document-tile.h> #include <libslab/double-click-detector.h> #include <libslab/mate-utils.h> #include <libslab/libslab-utils.h> diff --git a/libslab/system-tile.c b/libslab/system-tile.c index ce64cebe..995754ef 100644 --- a/libslab/system-tile.c +++ b/libslab/system-tile.c @@ -23,7 +23,6 @@ #include <string.h> #include <glib/gi18n-lib.h> -#include <mateconf/mateconf-client.h> #include "bookmark-agent.h" #include "slab-mate-util.h" |