diff --git a/ChangeLog b/ChangeLog index f73dd8f68011127a7f1f2cdcd4420def740fc5e9..08814ffef1e4838d3e3b64f3a91fde5eabb752ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-11-03 jeromeg + + * TODO: updated. + * lib/screenshooter-utils.h: add define for default application. + * lib/screenshooter-utils.c: + - (screenshooter_read_rc_file) read the default application. + - (screenshooter_write_rc_file) write the default application. + - (screenshooter_open_screenshot) only open if app != "none". + * lib/screenshooter-dialogs.c: + - add a define for icon size. + - (set_default_item) added to select the correct item of the combobox when + displaying the interface. + - (add_item) use the icon size define. + - (populate_liststore) add the "none" item on the top of the liststore. + - (screenshooter_dialog_new) add a call to set_default_item. + 2008-11-02 jeromeg * lib/screenshooter-dialogs.c: diff --git a/TODO b/TODO index 958451a8da12433e6144ac02e06fc7122e48aa03..f32780b201dcfe5440bef46d251761b2bb47be99 100755 --- a/TODO +++ b/TODO @@ -1,9 +1,8 @@ -* Save the chosen application to open screenshots with, and set it as active when creating the combobox. * Add open with support to the plugin. * Write some documentation. * Update the code comments. * Update the website. -* Correctly free the stuff in the GLists and liststore in screenshooter-dialogs.c +* Correctly free the stuff in the GLists in screenshooter-dialogs.c Low priority: * Try to get borders captured with compiz. diff --git a/lib/screenshooter-dialogs.c b/lib/screenshooter-dialogs.c index 5b740bf3d76f968553303730ab1e93c5fa57ab93..1d7cea113f9286f204a52f1b7ce550d8dcf605d5 100644 --- a/lib/screenshooter-dialogs.c +++ b/lib/screenshooter-dialogs.c @@ -19,6 +19,8 @@ #include "screenshooter-dialogs.h" +#define ICON_SIZE 22 + /* Prototypes */ static void cb_fullscreen_screen_toggled (GtkToggleButton *tb, @@ -36,7 +38,9 @@ static void cb_combo_active_item_changed (GtkComboBox *box, ScreenshotData *sd); static void add_item (GAppInfo *app_info, GtkWidget *liststore); -static void populate_liststore (GtkListStore *liststore); +static void populate_liststore (GtkListStore *liststore); +static void set_default_item (GtkWidget *combobox, + gchar *default_app); #endif @@ -134,7 +138,7 @@ static void add_item (GAppInfo *app_info, GtkWidget *liststore) gchar *path = g_file_get_path (file); pixbuf = - gdk_pixbuf_new_from_file_at_size (path, 22, 22, NULL); + gdk_pixbuf_new_from_file_at_size (path, ICON_SIZE, ICON_SIZE, NULL); g_free (path); g_object_unref (file); @@ -154,7 +158,7 @@ static void add_item (GAppInfo *app_info, GtkWidget *liststore) pixbuf = gtk_icon_theme_load_icon (icon_theme, names[0], - 22, + ICON_SIZE, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); } @@ -181,6 +185,16 @@ static void populate_liststore (GtkListStore *liststore) { const gchar *content_type; GList *list_app; + GtkTreeIter iter; + + gtk_list_store_append (GTK_LIST_STORE (liststore), &iter); + + gtk_list_store_set (GTK_LIST_STORE (liststore), + &iter, + 0, NULL, + 1, _("Do not open screenshots"), + 2, "none", + -1); content_type = "image/png"; @@ -193,6 +207,30 @@ static void populate_liststore (GtkListStore *liststore) g_list_free (list_app); } } + +static void set_default_item (GtkWidget *combobox, + gchar *default_app) +{ + GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox)); + GtkTreeIter iter; + gchar *command = NULL; + + gtk_tree_model_get_iter_first (model , &iter); + + do + { + gtk_tree_model_get (model, &iter, 2, &command, -1); + + if (g_str_equal (command, default_app)) + { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter); + break; + } + + g_free (command); + } + while (gtk_tree_model_iter_next (model, &iter)); +} #endif @@ -385,6 +423,8 @@ GtkWidget *screenshooter_dialog_new (ScreenshotData *sd, gboolean plugin) populate_liststore (liststore); + set_default_item (combobox, sd->app); + gtk_container_add (GTK_CONTAINER (options_box), combobox); g_signal_connect (G_OBJECT (combobox), "changed", diff --git a/lib/screenshooter-utils.c b/lib/screenshooter-utils.c index dc8b335c70f8223bd9af03ec5949edb993fd78c2..14ce0d980f173526d3576f0e7f529a0f7010d70a 100644 --- a/lib/screenshooter-utils.c +++ b/lib/screenshooter-utils.c @@ -290,6 +290,7 @@ screenshooter_read_rc_file (gchar *file, gint mode = FULLSCREEN; gint show_save_dialog = 1; gchar *screenshot_dir = g_strdup (DEFAULT_SAVE_DIRECTORY); + gchar *app = DEFAULT_APPLICATION; if (g_file_test (file, G_FILE_TEST_EXISTS)) { @@ -303,6 +304,8 @@ screenshooter_read_rc_file (gchar *file, mode = xfce_rc_read_int_entry (rc, "mode", FULLSCREEN); show_save_dialog = xfce_rc_read_int_entry (rc, "show_save_dialog", 1); + app = + g_strdup (xfce_rc_read_entry (rc, "app", DEFAULT_APPLICATION)); } g_free (screenshot_dir); @@ -320,6 +323,7 @@ screenshooter_read_rc_file (gchar *file, sd->mode = mode; sd->show_save_dialog = show_save_dialog; sd->screenshot_dir = screenshot_dir; + sd->app = app; } @@ -338,6 +342,7 @@ screenshooter_write_rc_file (gchar *file, xfce_rc_write_int_entry (rc, "mode", sd->mode); xfce_rc_write_int_entry (rc, "show_save_dialog", sd->show_save_dialog); xfce_rc_write_entry (rc, "screenshot_dir", sd->screenshot_dir); + xfce_rc_write_entry (rc, "app", sd->app); xfce_rc_close (rc); } @@ -350,8 +355,12 @@ screenshooter_open_screenshot (gchar *screenshot_path, { if (screenshot_path != NULL) { - gchar *command = g_strconcat (application, " ", screenshot_path, NULL); + if (!g_str_equal (application, "none")) + { + gchar *command = + g_strconcat (application, " ", screenshot_path, NULL); - xfce_exec (command, FALSE, TRUE, NULL); + xfce_exec (command, FALSE, TRUE, NULL); + } } } diff --git a/lib/screenshooter-utils.h b/lib/screenshooter-utils.h index 5306d46366d3522faf98c8c7ca6742969783b0c6..ae20904eb32cf8392d5d09efb3b7ba2cf1e06017 100644 --- a/lib/screenshooter-utils.h +++ b/lib/screenshooter-utils.h @@ -34,6 +34,7 @@ #include <unistd.h> #define DEFAULT_SAVE_DIRECTORY xfce_get_homedir () +#define DEFAULT_APPLICATION "none" enum { MODE_0,