[Goodies-commits] r6156 - in xfce4-screenshooter-plugin/trunk: . lib panel-plugin src
Jerome Guelfucci
jeromeg at xfce.org
Sat Nov 22 14:23:20 CET 2008
Author: jeromeg
Date: 2008-11-22 13:23:20 +0000 (Sat, 22 Nov 2008)
New Revision: 6156
Modified:
xfce4-screenshooter-plugin/trunk/ChangeLog
xfce4-screenshooter-plugin/trunk/lib/Makefile.am
xfce4-screenshooter-plugin/trunk/lib/libscreenshooter.h
xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.c
xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.h
xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.c
xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.h
xfce4-screenshooter-plugin/trunk/panel-plugin/screenshooter-plugin.c
xfce4-screenshooter-plugin/trunk/src/main.c
Log:
First step towards adding "copy to clipboard" functionnality. This commits may break a few things which will be fixed later. Based on the work of David Collins.
* lib/screenshooter-utils.{c,h}:
- fix includes
- cleanup prototypes
- (screenshooter_copy_to_clipboard) Partially apply a patch by
David Collins to add copying to clipboard possibility.
- add post screenshot actions in the ScreenshotData struct, in
(screenshooter_read_rc_file) and in (screenshooter_write_rc_file)
(Patch by David Collins).
- remove all references to "none" application.
* lib/screenshooter-dialogs.{c,h}:
- remove all references to none application.
- remove (cb_combo_active_item_set_sensitive).
- remove "none" item from (add_item).
* lib/screenshooter-actions.{c,h}:
- added to manage post screenshot actions.
* lib/Mafile.am: add new source files.
* lib/libscreenshooter.h: include screenshooter-actions.h.
* src/main.c, panel-plugin/screenshooter-plugin.c:
- use (screenshooter_take_and_output_screenshot).
Modified: xfce4-screenshooter-plugin/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter-plugin/trunk/ChangeLog 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/ChangeLog 2008-11-22 13:23:20 UTC (rev 6156)
@@ -1,3 +1,25 @@
+2008-11-22 jeromeg
+
+ * lib/screenshooter-utils.{c,h}:
+ - fix includes
+ - cleanup prototypes
+ - (screenshooter_copy_to_clipboard) Partially apply a patch by
+ David Collins to add copying to clipboard possibility.
+ - add post screenshot actions in the ScreenshotData struct, in
+ (screenshooter_read_rc_file) and in (screenshooter_write_rc_file)
+ (Patch by David Collins).
+ - remove all references to "none" application.
+ * lib/screenshooter-dialogs.{c,h}:
+ - remove all references to none application.
+ - remove (cb_combo_active_item_set_sensitive).
+ - remove "none" item from (add_item).
+ * lib/screenshooter-actions.{c,h}:
+ - added to manage post screenshot actions.
+ * lib/Mafile.am: add new source files.
+ * lib/libscreenshooter.h: include screenshooter-actions.h.
+ * src/main.c, panel-plugin/screenshooter-plugin.c:
+ - use (screenshooter_take_and_output_screenshot).
+
2008-11-16 jeromeg
* lib/screenshooter-utils.c, lib/screenshooter-dialogs.c
Modified: xfce4-screenshooter-plugin/trunk/lib/Makefile.am
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/Makefile.am 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/lib/Makefile.am 2008-11-22 13:23:20 UTC (rev 6156)
@@ -4,7 +4,8 @@
libscreenshooter_la_SOURCES = \
libscreenshooter.h \
screenshooter-utils.c screenshooter-utils.h \
- screenshooter-dialogs.c screenshooter-dialogs.h
+ screenshooter-dialogs.c screenshooter-dialogs.h \
+ screenshooter-actions.c screenshooter-actions.h
libscreenshooter_la_CFLAGS = \
-I$(top_srcdir) \
Modified: xfce4-screenshooter-plugin/trunk/lib/libscreenshooter.h
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/libscreenshooter.h 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/lib/libscreenshooter.h 2008-11-22 13:23:20 UTC (rev 6156)
@@ -22,5 +22,6 @@
#include "screenshooter-dialogs.h"
#include "screenshooter-utils.h"
+#include "screenshooter-actions.h"
#endif
Modified: xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.c 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.c 2008-11-22 13:23:20 UTC (rev 6156)
@@ -46,9 +46,6 @@
cb_combo_active_item_changed (GtkWidget *box,
ScreenshotData *sd);
static void
-cb_combo_active_item_set_sensitive (GtkWidget *box,
- GtkWidget *button);
-static void
add_item (GAppInfo *app_info,
GtkWidget *liststore);
static void
@@ -205,31 +202,6 @@
-static void cb_combo_active_item_set_sensitive (GtkWidget *box,
- GtkWidget *button)
-{
- GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (box));
- GtkTreeIter iter;
- gchar *active_command = NULL;
-
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (box), &iter);
-
- gtk_tree_model_get (model, &iter, 2, &active_command, -1);
-
- if (g_str_equal (active_command, "none"))
- {
- gtk_widget_set_sensitive (button, TRUE);
- }
- else
- {
- gtk_widget_set_sensitive (button, FALSE);
- }
-
- g_free (active_command);
-}
-
-
-
/* Extract the informations from app_info and add them to the liststore. */
static void add_item (GAppInfo *app_info, GtkWidget *liststore)
{
@@ -302,17 +274,6 @@
{
const gchar *content_type;
GList *list_app;
- GtkTreeIter iter;
-
- /* Add default "none" item. */
- 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";
@@ -466,14 +427,7 @@
{
/* Save option */
save_button = gtk_check_button_new_with_mnemonic (_("Show save dialog"));
-
- #ifdef HAVE_GIO
- if (!g_str_equal (sd->app, "none"))
- {
- gtk_widget_set_sensitive (save_button, FALSE);
- }
- #endif
-
+
gtk_widget_show (save_button);
gtk_box_pack_start (GTK_BOX (options_box), save_button, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (save_button),
@@ -568,13 +522,6 @@
g_signal_connect (G_OBJECT (combobox), "changed",
G_CALLBACK (cb_combo_active_item_changed), sd);
-
- if (plugin)
- {
- g_signal_connect (G_OBJECT (combobox), "changed",
- G_CALLBACK (cb_combo_active_item_set_sensitive),
- save_button);
- }
gtk_widget_show_all (combobox);
#endif
Modified: xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.h
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.h 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.h 2008-11-22 13:23:20 UTC (rev 6156)
@@ -21,21 +21,18 @@
#include <config.h>
#endif
-
-
-#include "screenshooter-utils.h"
#ifdef HAVE_GIO
#include <gio/gio.h>
#endif
-
-
#include <gtk/gtk.h>
#include <libxfce4util/libxfce4util.h>
#include <libxfcegui4/libxfcegui4.h>
+#include "screenshooter-utils.h"
+
GtkWidget
*screenshooter_dialog_new (ScreenshotData *sd,
gboolean plugin);
Modified: xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.c 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.c 2008-11-22 13:23:20 UTC (rev 6156)
@@ -17,27 +17,29 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <screenshooter-utils.h>
+#include "screenshooter-utils.h"
/* Prototypes */
+
+
+
static
Window find_toplevel_window (Window xid);
-static
-void cb_current_folder_changed (GtkFileChooser *chooser,
- gpointer user_data);
-static
-GdkWindow *get_active_window (GdkScreen *screen,
+
+static GdkWindow
+*get_active_window (GdkScreen *screen,
gboolean *needs_unref);
-static
-GdkPixbuf *get_window_screenshot (GdkWindow *window);
+static GdkPixbuf
+*get_window_screenshot (GdkWindow *window);
+
/* Borrowed from gnome-screenshot */
/* This function returns the toplevel window containing Window, for most
* window managers this will enable you to get the decorations around
- * Window. Does not work with Compiz.
+ * the window. Does not work with Compiz.
* Window: the X identifier of the window
* Returns: the X identifier of the toplevel window containing Window.*/
static Window
@@ -164,8 +166,7 @@
*sd: a ScreenshotData struct.
returns: the screenshot in a *GdkPixbuf.
*/
-GdkPixbuf *screenshooter_take_screenshot (gint mode,
- gint delay)
+GdkPixbuf *screenshooter_take_screenshot (gint mode, gint delay)
{
GdkPixbuf *screenshot;
GdkWindow *window = NULL;
@@ -206,6 +207,24 @@
+/* Copy the screenshot to the Clipboard.
+* Code is from gnome-screenshooter.
+* @screenshot: the screenshot
+*/
+void
+screenshooter_copy_to_clipboard (GdkPixbuf *screenshot)
+{
+ GtkClipboard *clipboard;
+
+ clipboard = gtk_clipboard_get_for_display (gdk_display_get_default(),
+ GDK_SELECTION_CLIPBOARD);
+ gtk_clipboard_set_image (clipboard, screenshot);
+
+ gtk_clipboard_store (clipboard);
+}
+
+
+
/* Read the options from file and sets the sd values.
@file: the path to the rc file.
@sd: the ScreenshotData to be set.
@@ -219,10 +238,11 @@
XfceRc *rc;
gint delay = 0;
gint mode = FULLSCREEN;
+ gint action = SAVE;
gint show_save_dialog = 1;
gchar *screenshot_dir = g_strdup (DEFAULT_SAVE_DIRECTORY);
#ifdef HAVE_GIO
- gchar *app = g_strdup (DEFAULT_APPLICATION);
+ gchar *app = NULL;
#endif
if (g_file_test (file, G_FILE_TEST_EXISTS))
@@ -234,18 +254,24 @@
if (!dir_only)
{
delay = xfce_rc_read_int_entry (rc, "delay", 0);
+
mode = xfce_rc_read_int_entry (rc, "mode", FULLSCREEN);
+
+ action = xfce_rc_read_int_entry (rc, "action", SAVE);
+
show_save_dialog =
xfce_rc_read_int_entry (rc, "show_save_dialog", 1);
+
#ifdef HAVE_GIO
g_free (app);
+
app =
- g_strdup (xfce_rc_read_entry (rc, "app",
- DEFAULT_APPLICATION));
+ g_strdup (xfce_rc_read_entry (rc, "app", NULL));
#endif
}
g_free (screenshot_dir);
+
screenshot_dir =
g_strdup (xfce_rc_read_entry (rc,
"screenshot_dir",
@@ -258,6 +284,7 @@
/* And set the sd values */
sd->delay = delay;
sd->mode = mode;
+ sd->action = action;
sd->show_save_dialog = show_save_dialog;
sd->screenshot_dir = screenshot_dir;
#ifdef HAVE_GIO
@@ -283,6 +310,7 @@
xfce_rc_write_int_entry (rc, "delay", sd->delay);
xfce_rc_write_int_entry (rc, "mode", sd->mode);
+ xfce_rc_write_int_entry (rc, "action", sd->action);
xfce_rc_write_int_entry (rc, "show_save_dialog",
sd->show_save_dialog);
xfce_rc_write_entry (rc, "screenshot_dir", sd->screenshot_dir);
@@ -306,25 +334,21 @@
{
if (screenshot_path != NULL)
{
- /* If application == none, we don't do anything */
- if (!g_str_equal (application, "none"))
- {
- gchar *command =
- g_strconcat (application, " ", screenshot_path, NULL);
+ gchar *command =
+ g_strconcat (application, " ", screenshot_path, NULL);
- GError *error = NULL;
+ GError *error = NULL;
- /* Execute the command and show an error dialog if there was
- * an error. */
- if (!xfce_exec_on_screen (gdk_screen_get_default (), command,
- FALSE, TRUE, &error))
- {
- xfce_err (error->message);
- g_error_free (error);
- }
+ /* Execute the command and show an error dialog if there was
+ * an error. */
+ if (!xfce_exec_on_screen (gdk_screen_get_default (), command,
+ FALSE, TRUE, &error))
+ {
+ xfce_err (error->message);
+ g_error_free (error);
+ }
- g_free (command);
- }
+ g_free (command);
}
}
-#endif
+#endif
Modified: xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.h
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.h 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.h 2008-11-22 13:23:20 UTC (rev 6156)
@@ -33,10 +33,7 @@
#include <unistd.h>
-
-
#define DEFAULT_SAVE_DIRECTORY xfce_get_homedir ()
-#define DEFAULT_APPLICATION "none"
@@ -49,19 +46,29 @@
+/* Possible actions */
+enum {
+ ACTION_0,
+ SAVE,
+ CLIPBOARD,
+ #ifdef HAVE_GIO
+ OPEN,
+ #endif
+};
+
+
+
/* Struct to store the screenshot options */
typedef struct
{
gint mode;
gint show_save_dialog;
-
gint delay;
+ gint action;
gchar *screenshot_dir;
-
#ifdef HAVE_GIO
gchar *app;
#endif
-
}
ScreenshotData;
@@ -70,7 +77,9 @@
GdkPixbuf
*screenshooter_take_screenshot (gint mode,
gint delay);
-
+void
+screenshooter_copy_to_clipboard (GdkPixbuf *screenshot) ;
+
void
screenshooter_read_rc_file (gchar *file,
ScreenshotData *sd,
Modified: xfce4-screenshooter-plugin/trunk/panel-plugin/screenshooter-plugin.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/panel-plugin/screenshooter-plugin.c 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/panel-plugin/screenshooter-plugin.c 2008-11-22 13:23:20 UTC (rev 6156)
@@ -154,43 +154,12 @@
static void
cb_button_clicked (GtkWidget *button, PluginData *pd)
{
- GdkPixbuf *screenshot;
- gchar *screenshot_path = NULL;
-
- /* Make the button unclickable so that the user does not press it while
+ /* Make the button unclickable so that the user does not press it while
another screenshot is in progress */
gtk_widget_set_sensitive (GTK_WIDGET (pd->button), FALSE);
- /* Get the screenshot */
- screenshot = screenshooter_take_screenshot (pd->sd->mode, pd->sd->delay);
+ screenshooter_take_and_output_screenshot (pd->sd);
- #ifdef HAVE_GIO
- if (!g_str_equal(pd->sd->app, "none"))
- {
- screenshot_path =
- screenshooter_save_screenshot (screenshot, FALSE, "/tmp");
- }
- else
- {
- #endif
- screenshot_path =
- screenshooter_save_screenshot (screenshot, pd->sd->show_save_dialog,
- pd->sd->screenshot_dir);
- #ifdef HAVE_GIO
- }
- #endif
-
- g_object_unref (screenshot);
-
- /* Open the screenshot */
- if (screenshot_path != NULL)
- {
- #ifdef HAVE_GIO
- screenshooter_open_screenshot (screenshot_path, pd->sd->app);
- #endif
- g_free (screenshot_path);
- }
-
/* Make the panel button clickable */
gtk_widget_set_sensitive (GTK_WIDGET (pd->button), TRUE);
}
Modified: xfce4-screenshooter-plugin/trunk/src/main.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/src/main.c 2008-11-22 12:04:15 UTC (rev 6155)
+++ xfce4-screenshooter-plugin/trunk/src/main.c 2008-11-22 13:23:20 UTC (rev 6156)
@@ -208,46 +208,10 @@
if (response == GTK_RESPONSE_OK)
{
- gchar *screenshot_path = NULL;
+ screenshooter_take_and_output_screenshot (sd);
- /* Take the screenshot */
- screenshot = screenshooter_take_screenshot (sd->mode, sd->delay);
-
- #ifdef HAVE_GIO
- if (!g_str_equal(sd->app, "none"))
- {
- screenshot_path =
- screenshooter_save_screenshot (screenshot,
- FALSE,
- "/tmp");
- }
- else
- {
- #endif
- screenshot_path =
- screenshooter_save_screenshot (screenshot,
- sd->show_save_dialog,
- sd->screenshot_dir);
- #ifdef HAVE_GIO
- }
- #endif
-
- g_object_unref (screenshot);
-
- /* Open the screenshot */
-
- if (screenshot_path != NULL)
- {
- #ifdef HAVE_GIO
- screenshooter_open_screenshot (screenshot_path, sd->app);
- #endif
- g_free (screenshot_path);
- }
-
-
/* Save preferences */
screenshooter_write_rc_file (rc_file, sd);
-
}
}
More information about the Goodies-commits
mailing list