diff options
Diffstat (limited to 'mate-panel/panel-run-dialog.c')
-rw-r--r-- | mate-panel/panel-run-dialog.c | 180 |
1 files changed, 56 insertions, 124 deletions
diff --git a/mate-panel/panel-run-dialog.c b/mate-panel/panel-run-dialog.c index 01c35deb..51a6be7c 100644 --- a/mate-panel/panel-run-dialog.c +++ b/mate-panel/panel-run-dialog.c @@ -87,14 +87,12 @@ typedef struct { GList *completion_items; GCompletion *completion; - GSList *add_icon_paths; - int add_icons_idle_id; int add_items_idle_id; int find_command_idle_id; gboolean use_program_list; gboolean completion_started; - char *icon_path; + GIcon *icon; char *desktop_path; char *item_name; @@ -102,8 +100,7 @@ typedef struct { } PanelRunDialog; enum { - COLUMN_ICON, - COLUMN_ICON_FILE, + COLUMN_GICON, COLUMN_NAME, COLUMN_COMMENT, COLUMN_PATH, @@ -188,21 +185,12 @@ panel_run_dialog_destroy (PanelRunDialog *dialog) g_object_unref (dialog->program_list_box); - g_slist_foreach (dialog->add_icon_paths, (GFunc) gtk_tree_path_free, NULL); - g_slist_free (dialog->add_icon_paths); - dialog->add_icon_paths = NULL; - - g_free (dialog->icon_path); - dialog->icon_path = NULL; + g_clear_object (&(dialog->icon)); g_free (dialog->desktop_path); dialog->desktop_path = NULL; g_free (dialog->item_name); dialog->item_name = NULL; - if (dialog->add_icons_idle_id) - g_source_remove (dialog->add_icons_idle_id); - dialog->add_icons_idle_id = 0; - if (dialog->add_items_idle_id) g_source_remove (dialog->add_items_idle_id); dialog->add_items_idle_id = 0; @@ -255,39 +243,34 @@ panel_run_dialog_set_default_icon (PanelRunDialog *dialog, gboolean set_drag) static void panel_run_dialog_set_icon (PanelRunDialog *dialog, - const char *icon_path, + GIcon *icon, gboolean force) { GdkPixbuf *pixbuf = NULL; - if (!force && icon_path && dialog->icon_path && - !strcmp (icon_path, dialog->icon_path)) + if (!force && g_icon_equal(icon, dialog->icon)) return; - g_free (dialog->icon_path); - dialog->icon_path = NULL; + g_clear_object(&(dialog->icon)); - if (icon_path) { - GdkScreen *screen; - GtkSettings *settings; + if (icon) { int size; - screen = gtk_widget_get_screen (GTK_WIDGET (dialog->pixmap)); - settings = gtk_settings_get_for_screen (screen); - gtk_icon_size_lookup_for_settings (settings, - GTK_ICON_SIZE_DIALOG, - &size, NULL); - - pixbuf = panel_load_icon (gtk_icon_theme_get_default (), - icon_path, - size, - size, - size, - NULL); + gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, NULL); + + GtkIconTheme *icon_theme = gtk_icon_theme_get_default (); + GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, size, 0); + pixbuf = gtk_icon_info_load_icon (icon_info, NULL); +#if GTK_CHECK_VERSION (3, 8, 0) + g_object_unref (icon_info); +#else + gtk_icon_info_free (icon_info); +#endif + } if (pixbuf) { - dialog->icon_path = g_strdup (icon_path); + dialog->icon = g_object_ref (icon); /* Don't bother scaling the image if it's too small. * Scaled looks worse than a smaller image. @@ -298,7 +281,11 @@ panel_run_dialog_set_icon (PanelRunDialog *dialog, //(ditto for the drag icon?) gtk_window_set_icon (GTK_WINDOW (dialog->run_dialog), pixbuf); +#if GTK_CHECK_VERSION (3, 2, 0) + gtk_drag_source_set_icon_gicon (dialog->run_dialog, dialog->icon); +#else gtk_drag_source_set_icon_pixbuf (dialog->run_dialog, pixbuf); +#endif g_object_unref (pixbuf); } else { panel_run_dialog_set_default_icon (dialog, TRUE); @@ -667,7 +654,7 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog) GtkTreeModel *model; GtkTreePath *path; char *text; - char *found_icon; + GIcon *found_icon; char *found_name; gboolean fuzzy; @@ -691,23 +678,23 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog) do { char *exec = NULL; - char *icon = NULL; + GIcon *icon = NULL; char *name = NULL; char *comment = NULL; gtk_tree_model_get (model, &iter, COLUMN_EXEC, &exec, - COLUMN_ICON_FILE, &icon, + COLUMN_GICON, &icon, COLUMN_NAME, &name, COLUMN_COMMENT, &comment, -1); if (!fuzzy && exec && icon && fuzzy_command_match (text, exec, &fuzzy)) { - g_free (found_icon); + g_clear_object (&found_icon); g_free (found_name); - found_icon = g_strdup (icon); + found_icon = g_object_ref (icon); found_name = g_strdup (name); gtk_list_store_set (dialog->program_list_store, @@ -729,7 +716,7 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog) } g_free (exec); - g_free (icon); + g_object_unref (icon); g_free (name); g_free (comment); @@ -745,7 +732,7 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog) panel_run_dialog_set_icon (dialog, found_icon, FALSE); //FIXME update dialog->program_label - g_free (found_icon); + g_clear_object (&found_icon); g_free (text); g_free (dialog->item_name); @@ -755,56 +742,6 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog) return FALSE; } -static gboolean -panel_run_dialog_add_icon_idle (PanelRunDialog *dialog) -{ - GtkTreeIter iter; - GtkTreePath *path; - GdkPixbuf *pixbuf; - char *file; - int icon_height; - gboolean long_operation = FALSE; - - do { - if (!dialog->add_icon_paths) { - dialog->add_icons_idle_id = 0; - return FALSE; - } - - path = dialog->add_icon_paths->data; - dialog->add_icon_paths->data = NULL; - dialog->add_icon_paths = g_slist_delete_link (dialog->add_icon_paths, - dialog->add_icon_paths); - - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (dialog->program_list_store), - &iter, - path)) { - gtk_tree_path_free (path); - continue; - } - - gtk_tree_path_free (path); - - gtk_tree_model_get (GTK_TREE_MODEL (dialog->program_list_store), &iter, - COLUMN_ICON_FILE, &file, -1); - - if (!gtk_icon_size_lookup (panel_menu_icon_get_size (), NULL, &icon_height)) { - icon_height = PANEL_DEFAULT_MENU_ICON_SIZE; - } - - pixbuf = panel_make_menu_icon (gtk_icon_theme_get_default (), file, NULL, icon_height, &long_operation); - if (pixbuf) { - gtk_list_store_set (dialog->program_list_store, &iter, COLUMN_ICON, pixbuf, -1); - g_object_unref (pixbuf); - } - g_free (file); - - /* don't go back into the main loop if this wasn't very hard to do */ - } while (!long_operation); - - return TRUE; -} - static int compare_applications (MateMenuTreeEntry *a, MateMenuTreeEntry *b) @@ -912,8 +849,7 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog) /* create list store */ dialog->program_list_store = gtk_list_store_new (NUM_COLUMNS, - GDK_TYPE_PIXBUF, - G_TYPE_STRING, + G_TYPE_ICON, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, @@ -943,12 +879,12 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog) for (l = all_applications; l; l = l->next) { MateMenuTreeEntry *entry = l->data; GtkTreeIter iter; - GtkTreePath *path; + const gchar *icon = matemenu_tree_entry_get_icon (entry); + GIcon *gicon = panel_gicon_from_icon_name (icon); gtk_list_store_append (dialog->program_list_store, &iter); gtk_list_store_set (dialog->program_list_store, &iter, - COLUMN_ICON, NULL, - COLUMN_ICON_FILE, matemenu_tree_entry_get_icon (entry), + COLUMN_GICON, gicon, COLUMN_NAME, matemenu_tree_entry_get_display_name (entry), COLUMN_COMMENT, matemenu_tree_entry_get_comment (entry), COLUMN_EXEC, matemenu_tree_entry_get_exec (entry), @@ -956,9 +892,7 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog) COLUMN_VISIBLE, TRUE, -1); - path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->program_list_store), &iter); - if (path != NULL) - dialog->add_icon_paths = g_slist_prepend (dialog->add_icon_paths, path); + g_object_unref (gicon); matemenu_tree_item_unref (entry); } @@ -976,10 +910,11 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog) COLUMN_NAME); renderer = gtk_cell_renderer_pixbuf_new (); + g_object_set (renderer, "stock-size", panel_menu_icon_get_size(), NULL); column = gtk_tree_view_column_new (); gtk_tree_view_column_pack_start (column, renderer, FALSE); gtk_tree_view_column_set_attributes (column, renderer, - "pixbuf", COLUMN_ICON, + "gicon", COLUMN_GICON, NULL); renderer = gtk_cell_renderer_text_new (); @@ -990,15 +925,8 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog) gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->program_list), column); - dialog->add_icon_paths = g_slist_reverse (dialog->add_icon_paths); - - if (!dialog->add_icons_idle_id) - dialog->add_icons_idle_id = - g_idle_add_full (G_PRIORITY_LOW, (GSourceFunc) panel_run_dialog_add_icon_idle, - dialog, NULL); - dialog->add_items_idle_id = 0; - return FALSE; + return G_SOURCE_REMOVE; } static char * @@ -1104,7 +1032,9 @@ program_list_selection_changed (GtkTreeSelection *selection, g_free (temp); temp = panel_key_file_get_locale_string (key_file, "Icon"); - panel_run_dialog_set_icon (dialog, temp, FALSE); + GIcon *icon = panel_gicon_from_icon_name (temp); + panel_run_dialog_set_icon (dialog, icon, FALSE); + g_object_unref (icon); g_free (temp); temp = panel_key_file_get_locale_string (key_file, "Comment"); @@ -1842,9 +1772,11 @@ panel_run_dialog_create_desktop_file (PanelRunDialog *dialog) panel_key_file_set_boolean (key_file, "Terminal", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox))); - if (dialog->icon_path) - panel_key_file_set_locale_string (key_file, "Icon", - dialog->icon_path); + if (dialog->icon) { + gchar *icon_path = g_icon_to_string (dialog->icon); + panel_key_file_set_locale_string (key_file, "Icon", icon_path); + g_free (icon_path); + } else panel_key_file_set_locale_string (key_file, "Icon", PANEL_ICON_LAUNCHER); @@ -1893,12 +1825,12 @@ panel_run_dialog_style_set (GtkWidget *widget, GtkStyle *prev_style, PanelRunDialog *dialog) { - if (dialog->icon_path) { - char *icon_path; + if (dialog->icon) { + GIcon *icon; - icon_path = g_strdup (dialog->icon_path); - panel_run_dialog_set_icon (dialog, icon_path, TRUE); - g_free (icon_path); + icon = g_object_ref (dialog->icon); + panel_run_dialog_set_icon (dialog, icon, TRUE); + g_object_unref (icon); } } @@ -1907,12 +1839,12 @@ panel_run_dialog_screen_changed (GtkWidget *widget, GdkScreen *prev_screen, PanelRunDialog *dialog) { - if (dialog->icon_path) { - char *icon_path; + if (dialog->icon) { + GIcon *icon; - icon_path = g_strdup (dialog->icon_path); - panel_run_dialog_set_icon (dialog, icon_path, TRUE); - g_free (icon_path); + icon = g_object_ref (dialog->icon); + panel_run_dialog_set_icon (dialog, icon, TRUE); + g_object_unref (icon);; } } |