static const MateThemeMetaInfo * theme_get_selected (GtkIconView *icon_view, AppearanceData *data) { MateThemeMetaInfo *theme = NULL; gchar *name = theme_get_selected_name (icon_view, data); if (name != NULL) { if (!strcmp (name, data->theme_custom->name)) { theme = data->theme_custom; } else { theme = mate_theme_meta_info_find (name); } g_free (name); } return theme; }
static void theme_selection_changed_cb (GtkWidget *icon_view, AppearanceData *data) { GList *selection; MateThemeMetaInfo *theme = NULL; gboolean is_custom = FALSE; selection = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (icon_view)); if (selection) { GtkTreeModel *model; GtkTreeIter iter; gchar *name; model = gtk_icon_view_get_model (GTK_ICON_VIEW (icon_view)); gtk_tree_model_get_iter (model, &iter, selection->data); gtk_tree_model_get (model, &iter, COL_NAME, &name, -1); is_custom = !strcmp (name, CUSTOM_THEME_NAME); if (is_custom) theme = data->theme_custom; else theme = mate_theme_meta_info_find (name); if (theme) { mate_meta_theme_set (theme); theme_message_area_update (data); } g_free (name); g_list_foreach (selection, (GFunc) gtk_tree_path_free, NULL); g_list_free (selection); } gtk_widget_set_sensitive (appearance_capplet_get_widget (data, "theme_delete"), theme_is_writable (theme)); gtk_widget_set_sensitive (appearance_capplet_get_widget (data, "theme_save"), is_custom); }
static time_t theme_get_mtime(const char* name) { MateThemeMetaInfo* theme; time_t mtime = -1; theme = mate_theme_meta_info_find(name); if (theme != NULL) { GFile* file; GFileInfo* file_info; file = g_file_new_for_path(theme->path); file_info = g_file_query_info(file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref(file); if (file_info != NULL) { mtime = g_file_info_get_attribute_uint64(file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED); g_object_unref(file_info); } } return mtime; }
gboolean theme_delete (const gchar *name, ThemeType type) { gboolean rc; GtkDialog *dialog; gchar *theme_dir; gint response; MateThemeCommonInfo *theme; GFile *dir; gboolean del_empty_parent; dialog = (GtkDialog *) gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL, _("Would you like to delete this theme?")); #if GTK_CHECK_VERSION (3, 10, 0) gtk_dialog_add_button (dialog, _("_Delete"), GTK_RESPONSE_ACCEPT); #else gtk_dialog_add_button (dialog, GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT); #endif response = gtk_dialog_run (dialog); gtk_widget_destroy (GTK_WIDGET (dialog)); if (response != GTK_RESPONSE_ACCEPT) return FALSE; /* Most theme types are put into separate subdirectories. For those we want to delete those directories as well. */ del_empty_parent = TRUE; switch (type) { case THEME_TYPE_GTK: theme = (MateThemeCommonInfo *) mate_theme_info_find (name); theme_dir = g_build_filename (theme->path, "gtk-2.0", NULL); break; case THEME_TYPE_ICON: theme = (MateThemeCommonInfo *) mate_theme_icon_info_find (name); theme_dir = g_path_get_dirname (theme->path); del_empty_parent = FALSE; break; case THEME_TYPE_WINDOW: theme = (MateThemeCommonInfo *) mate_theme_info_find (name); theme_dir = g_build_filename (theme->path, "marco-1", NULL); break; case THEME_TYPE_META: theme = (MateThemeCommonInfo *) mate_theme_meta_info_find (name); theme_dir = g_strdup (theme->path); break; case THEME_TYPE_CURSOR: theme = (MateThemeCommonInfo *) mate_theme_cursor_info_find (name); theme_dir = g_build_filename (theme->path, "cursors", NULL); break; default: return FALSE; } dir = g_file_new_for_path (theme_dir); g_free (theme_dir); if (!capplet_file_delete_recursive (dir, NULL)) { GtkWidget *info_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Theme cannot be deleted")); gtk_dialog_run (GTK_DIALOG (info_dialog)); gtk_widget_destroy (info_dialog); rc = FALSE; } else { if (del_empty_parent) { /* also delete empty parent directories */ GFile *parent = g_file_get_parent (dir); g_file_delete (parent, NULL, NULL); g_object_unref (parent); } rc = TRUE; } g_object_unref (dir); return rc; }