[Goodies-commits] r5278 - in xfce4-screenshooter-plugin/trunk: . src
Jerome Guelfucci
jeromeg at xfce.org
Tue Aug 19 12:58:54 CEST 2008
Author: jeromeg
Date: 2008-08-19 10:58:54 +0000 (Tue, 19 Aug 2008)
New Revision: 5278
Modified:
xfce4-screenshooter-plugin/trunk/ChangeLog
xfce4-screenshooter-plugin/trunk/NEWS
xfce4-screenshooter-plugin/trunk/src/main.c
xfce4-screenshooter-plugin/trunk/src/screenshooter-plugin.c
xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.c
xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.h
Log:
* src/*:
- comment all code
- clean identation
- plug some leaks of GdkPixbuf
* NEWS: updated.
Modified: xfce4-screenshooter-plugin/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter-plugin/trunk/ChangeLog 2008-08-18 23:18:34 UTC (rev 5277)
+++ xfce4-screenshooter-plugin/trunk/ChangeLog 2008-08-19 10:58:54 UTC (rev 5278)
@@ -1,3 +1,11 @@
+2008-08-19 jeromeg
+
+ * src/*:
+ - comment all code
+ - clean identation
+ - plug some leaks of GdkPixbuf.
+ * NEWS: updated.
+
2008-08-16 jeromeg
* xfce4-screenshooter.1: bump version for future release.
Modified: xfce4-screenshooter-plugin/trunk/NEWS
===================================================================
--- xfce4-screenshooter-plugin/trunk/NEWS 2008-08-18 23:18:34 UTC (rev 5277)
+++ xfce4-screenshooter-plugin/trunk/NEWS 2008-08-19 10:58:54 UTC (rev 5278)
@@ -5,6 +5,7 @@
* Code cleanup using libgdk functions.
* Use tooltips for panel plugin when compiled with gtk >= 2.12.
* Fix all compiler warnings.
+ * Comment the code and make it more readable.
=== Version 1.3.1 ===
* BUGFIX: Fix -s switch with relative path.
Modified: xfce4-screenshooter-plugin/trunk/src/main.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/src/main.c 2008-08-18 23:18:34 UTC (rev 5277)
+++ xfce4-screenshooter-plugin/trunk/src/main.c 2008-08-19 10:58:54 UTC (rev 5278)
@@ -23,13 +23,22 @@
#include "screenshooter-utils.h"
+
+
+/* Set default values for cli args */
gboolean version = FALSE;
gboolean window = FALSE;
gboolean no_save_dialog = FALSE;
gboolean preferences = FALSE;
-gchar * screenshot_dir;
+gchar *screenshot_dir;
gint delay = 0;
+
+
+/* Set cli options. The -p option creates a conf file named xfce4-screenshooter
+ in ~/.config/xfce4/. This file only contains one entry, the name of the
+ default save folder.
+*/
static GOptionEntry entries[] =
{
{ "version", 'v', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version,
@@ -60,126 +69,150 @@
{ NULL }
};
+
+
int main(int argc, char **argv)
{
GError *cli_error = NULL;
- GdkPixbuf * screenshot;
- ScreenshotData * sd = g_new0 (ScreenshotData, 1);
+ GdkPixbuf *screenshot;
+ ScreenshotData *sd = g_new0 (ScreenshotData, 1);
XfceRc *rc;
- gchar * rc_file;
-
- rc_file = g_build_filename( xfce_get_homedir(), ".config", "xfce4",
+ gchar *rc_file;
+
+ /* Get the path to the conf file */
+ rc_file = g_build_filename (xfce_get_homedir(), ".config", "xfce4",
"xfce4-screenshooter", NULL);
-
- if ( g_file_test(rc_file, G_FILE_TEST_EXISTS) )
- {
- rc = xfce_rc_simple_open (rc_file, TRUE);
- screenshot_dir = g_strdup ( xfce_rc_read_entry (rc, "screenshot_dir",
- xfce_get_homedir () ) );
- sd->screenshot_dir = screenshot_dir;
- xfce_rc_close (rc);
- }
+
+ /* If the file exists, we parse it to get the default save folder. Else we use
+ the home dir. */
+ if (g_file_test (rc_file, G_FILE_TEST_EXISTS))
+ {
+ rc = xfce_rc_simple_open (rc_file, TRUE);
+ screenshot_dir = g_strdup (xfce_rc_read_entry (rc, "screenshot_dir",
+ xfce_get_homedir ()));
+ sd->screenshot_dir = screenshot_dir;
+ xfce_rc_close (rc);
+ }
else
- {
- screenshot_dir = g_strdup( xfce_get_homedir () );
- sd->screenshot_dir = screenshot_dir;
- }
+ {
+ screenshot_dir = g_strdup (xfce_get_homedir ());
+ sd->screenshot_dir = screenshot_dir;
+ }
- xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
-
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+ /* Print a message to advise to use help when a non existing cli option is
+ passed to the executable. */
if (!gtk_init_with_args(&argc, &argv, _(""), entries, PACKAGE, &cli_error))
- {
- if (cli_error != NULL)
{
- g_print (_("%s: %s\nTry %s --help to see a full list of available command line options.\n"),
- PACKAGE, cli_error->message, PACKAGE_NAME);
- g_error_free (cli_error);
- return 1;
+ if (cli_error != NULL)
+ {
+ g_print (_("%s: %s\nTry %s --help to see a full list of available command line options.\n"),
+ PACKAGE, cli_error->message, PACKAGE_NAME);
+ g_error_free (cli_error);
+ return 1;
+ }
}
- }
+ /* Just print the version if we are in version mode */
if (version)
- {
- g_print("%s\n", PACKAGE_STRING);
- return 0;
- }
+ {
+ g_print ("%s\n", PACKAGE_STRING);
+ return 0;
+ }
+ /* If -w is given to the executable, grab the active window, else just grab
+ the desktop.*/
if (window)
- {
- sd->whole_screen = 0;
- }
+ {
+ sd->whole_screen = 0;
+ }
else
- {
- sd->whole_screen = 1;
- }
+ {
+ sd->whole_screen = 1;
+ }
+ /* Wether to show the save dialog allowing to choose a filename and a save
+ location */
if (no_save_dialog)
- {
- sd->show_save_dialog = 0;
- }
+ {
+ sd->show_save_dialog = 0;
+ }
else
- {
- sd->show_save_dialog = 1;
- }
+ {
+ sd->show_save_dialog = 1;
+ }
sd->screenshot_delay = delay;
- if ( g_file_test (screenshot_dir, G_FILE_TEST_IS_DIR) )
- {
- if ( g_path_is_absolute ( screenshot_dir ) )
- {
- sd->screenshot_dir = screenshot_dir;
+ /* Verify that the user gave a valid directory name */
+ if (g_file_test (screenshot_dir, G_FILE_TEST_IS_DIR))
+ {
+ /* Check if the path is absolute, if not make it absolute */
+ if (g_path_is_absolute (screenshot_dir))
+ {
+ sd->screenshot_dir = screenshot_dir;
+ }
+ else
+ {
+ screenshot_dir =
+ g_build_filename (g_get_current_dir (), screenshot_dir, NULL);
+ sd->screenshot_dir = screenshot_dir;
+ }
}
- else
+ else
{
- screenshot_dir = g_build_filename(g_get_current_dir(), screenshot_dir, NULL);
- sd->screenshot_dir = screenshot_dir;
+ g_warning ("%s is not a valid directory, the default directory will be used.",
+ screenshot_dir);
}
- }
- else
- {
- g_warning ("%s is not a valid directory, the default directory will be used.", screenshot_dir);
- }
- if ( !preferences )
- {
- screenshot = take_screenshot( sd );
- save_screenshot (screenshot, sd);
- }
+ /* If -p is given, show the preferences dialog, else just take the screenshots
+ with the given options */
+ if (!preferences)
+ {
+ screenshot = take_screenshot (sd);
+ save_screenshot (screenshot, sd);
+
+ g_object_unref (screenshot);
+ }
else
- {
- GtkWidget * chooser;
- gint dialog_response;
- gchar * dir;
+ {
+ GtkWidget * chooser;
+ gint dialog_response;
+ gchar * dir;
+
+ /* The preferences dialog is a plain gtk_file_chooser, we just get the
+ folder the user selected and write it in the conf file*/
+ dir = screenshot_dir;
- dir = screenshot_dir;
+ chooser =
+ gtk_file_chooser_dialog_new (_("Default save folder"),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser), dir);
- chooser = gtk_file_chooser_dialog_new ( _("Default save folder"),
- NULL,
- GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_dialog_set_default_response (GTK_DIALOG ( chooser ), GTK_RESPONSE_ACCEPT);
- gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER ( chooser ), dir);
+ dialog_response = gtk_dialog_run(GTK_DIALOG (chooser));
- dialog_response = gtk_dialog_run( GTK_DIALOG ( chooser ) );
-
- if ( dialog_response == GTK_RESPONSE_ACCEPT )
- {
- dir = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( chooser ) );
+ if (dialog_response == GTK_RESPONSE_ACCEPT)
+ {
+ dir = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
- rc = xfce_rc_simple_open (rc_file, FALSE);
- xfce_rc_write_entry (rc, "screenshot_dir", dir);
- xfce_rc_close ( rc );
+ rc = xfce_rc_simple_open (rc_file, FALSE);
+ xfce_rc_write_entry (rc, "screenshot_dir", dir);
+ xfce_rc_close (rc);
- g_free( dir );
- }
- gtk_widget_destroy( GTK_WIDGET ( chooser ) );
- }
+ g_free (dir);
+ }
+ gtk_widget_destroy (GTK_WIDGET (chooser));
+ }
- g_free( sd->screenshot_dir );
- g_free ( sd );
- g_free( rc_file );
+ g_free (sd->screenshot_dir);
+ g_free (sd);
+ g_free (rc_file);
+
return 0;
}
Modified: xfce4-screenshooter-plugin/trunk/src/screenshooter-plugin.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/src/screenshooter-plugin.c 2008-08-18 23:18:34 UTC (rev 5277)
+++ xfce4-screenshooter-plugin/trunk/src/screenshooter-plugin.c 2008-08-19 10:58:54 UTC (rev 5278)
@@ -40,6 +40,7 @@
#define SCREENSHOT_ICON_NAME "applets-screenshooter"
+/* Struct containing all panel plugin data */
typedef struct
{
XfcePanelPlugin *plugin;
@@ -52,18 +53,47 @@
}
PluginData;
-/* Panel Plugin Interface */
+
+/* Protoypes */
+
static void screenshot_properties_dialog (XfcePanelPlugin *plugin,
PluginData *pd);
-static void screenshot_construct (XfcePanelPlugin * plugin);
+static void screenshot_construct (XfcePanelPlugin *plugin);
+static gboolean screenshot_set_size (XfcePanelPlugin *plugin,
+ int size, PluginData *pd);
+static void screenshot_free_data (XfcePanelPlugin *plugin,
+ PluginData *pd);
+static void button_clicked (GtkWidget *button, PluginData *pd);
+static void screenshot_style_set (XfcePanelPlugin *plugin, gpointer ignored,
+ PluginData *pd);
+static void screenshot_read_rc_file (XfcePanelPlugin *plugin, PluginData *pd);
+static void screenshot_write_rc_file (XfcePanelPlugin *plugin, PluginData *pd);
+static void show_save_dialog_toggled (GtkToggleButton *tb, PluginData *pd);
+static void whole_screen_toggled (GtkToggleButton *tb, PluginData *pd);
+static void active_window_toggled (GtkToggleButton *tb, PluginData *pd);
+static void screenshot_delay_spinner_changed (GtkWidget *spinner,
+ PluginData *pd);
+static void cb_default_folder (GtkWidget *chooser, PluginData *pd);
+static void screenshot_dialog_response (GtkWidget *dlg, int reponse,
+ PluginData *pd);
+
+
+/* Register the panel plugin */
XFCE_PANEL_PLUGIN_REGISTER_INTERNAL (screenshot_construct);
+
+
/* Internal functions */
+
+
+/* Modify the size of the panel button
+Returns TRUE if succesful.
+*/
static gboolean
-screenshot_set_size (XfcePanelPlugin *plugin, int size, PluginData * pd)
+screenshot_set_size (XfcePanelPlugin *plugin, int size, PluginData *pd)
{
GdkPixbuf *pb;
int width = size - 2 - 2 * MAX (pd->button->style->xthickness,
@@ -77,35 +107,55 @@
return TRUE;
}
+
+
+/* Free the panel plugin data stored in pd
+plugin: a XfcePanelPlugin (a screenshooter one).
+pd: the associated PluginData.
+*/
static void
-screenshot_free_data (XfcePanelPlugin * plugin, PluginData * pd)
+screenshot_free_data (XfcePanelPlugin *plugin, PluginData *pd)
{
if (pd->style_id)
g_signal_handler_disconnect (plugin, pd->style_id);
pd->style_id = 0;
- g_free( pd->sd->screenshot_dir );
- g_free( pd->sd );
- g_free( pd );
+ g_free (pd->sd->screenshot_dir);
+ g_free (pd->sd);
+ g_free (pd);
}
+
+
+/* Take the screenshot when the button is clicked.
+button: the panel button.
+pd: the PluginData storing the options for taking the screenshot.
+*/
static void
-button_clicked(GtkWidget * button, PluginData * pd)
+button_clicked (GtkWidget *button, PluginData *pd)
{
- GdkPixbuf * screenshot;
+ GdkPixbuf *screenshot;
/* 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);
+ gtk_widget_set_sensitive (GTK_WIDGET (pd->button), FALSE);
/* Get the screenshot */
- screenshot = take_screenshot( pd->sd );
+ screenshot = take_screenshot (pd->sd);
- save_screenshot(screenshot, pd->sd);
+ save_screenshot (screenshot, pd->sd);
- gtk_widget_set_sensitive(GTK_WIDGET ( pd->button ), TRUE);
+ gtk_widget_set_sensitive (GTK_WIDGET (pd->button), TRUE);
+
+ g_object_unref (screenshot);
}
+
+
+/* Set the style of the panel plugin.
+plugin: a XfcePanelPlugin (a screenshooter one).
+pd: the associated PluginData.
+*/
static void
screenshot_style_set (XfcePanelPlugin *plugin, gpointer ignored,
PluginData *pd)
@@ -113,6 +163,12 @@
screenshot_set_size (plugin, xfce_panel_plugin_get_size (plugin), pd);
}
+
+
+/* Read the rc file associated to the panel plugin and store the options in pd.
+plugin: a XfcePanelPlugin (a screenshooter one).
+pd: the associated PluginData.
+*/
static void
screenshot_read_rc_file (XfcePanelPlugin *plugin, PluginData *pd)
{
@@ -123,11 +179,12 @@
gint show_save_dialog = 1;
gchar *screenshot_dir = g_strdup (xfce_get_homedir ());
+ /* If there is an rc file, we read it */
if ( (file = xfce_panel_plugin_lookup_rc_file (plugin) ) != NULL)
{
rc = xfce_rc_simple_open (file, TRUE);
- if ( rc != NULL )
+ if ( rc != NULL)
{
screenshot_delay = xfce_rc_read_int_entry (rc, "screenshot_delay", 0);
whole_screen = xfce_rc_read_int_entry (rc, "whole_screen", 1);
@@ -142,26 +199,33 @@
g_free (file);
}
+ /* And set the pd values */
pd->sd->screenshot_delay = screenshot_delay;
pd->sd->whole_screen = whole_screen;
pd->sd->show_save_dialog = show_save_dialog;
pd->sd->screenshot_dir = screenshot_dir;
}
+
+
+/* Write the pd options in the rc file associated to plugin
+plugin: a XfcePanelPlugin (a screenshooter one).
+pd: the associated PluginData.
+*/
static void
screenshot_write_rc_file (XfcePanelPlugin *plugin, PluginData *pd)
{
char *file;
XfceRc *rc;
- if ( !(file = xfce_panel_plugin_save_location (plugin, TRUE)) )
- return;
+ if (!(file = xfce_panel_plugin_save_location (plugin, TRUE)))
+ return;
rc = xfce_rc_simple_open (file, FALSE);
g_free (file);
- if ( !rc )
- return;
+ if (!rc)
+ return;
xfce_rc_write_int_entry (rc, "screenshot_delay", pd->sd->screenshot_delay);
xfce_rc_write_int_entry (rc, "whole_screen", pd->sd->whole_screen);
@@ -171,39 +235,69 @@
xfce_rc_close (rc);
}
+
+
+/* Callback for save dialog:
+ Get the value of the toggle button and set the save dialog option.
+*/
static void
show_save_dialog_toggled (GtkToggleButton *tb, PluginData *pd)
{
- pd->sd->show_save_dialog = gtk_toggle_button_get_active ( tb );
+ pd->sd->show_save_dialog = gtk_toggle_button_get_active (tb);
}
+
+
+/* Callback for whole screen:
+ Get the value of the toggle button and set the whole screen option.
+*/
static void
whole_screen_toggled (GtkToggleButton *tb, PluginData *pd)
{
- pd->sd->whole_screen = gtk_toggle_button_get_active ( tb );
+ pd->sd->whole_screen = gtk_toggle_button_get_active (tb);
}
-/* If active window is chosen, we set whole_screen to false */
+
+
+/* Callback for active window:
+ Get the value of the toggle button and set the whole screen option.
+*/
static void
active_window_toggled (GtkToggleButton *tb, PluginData *pd)
{
- pd->sd->whole_screen = !gtk_toggle_button_get_active ( tb );
+ pd->sd->whole_screen = !gtk_toggle_button_get_active (tb);
}
+
+
+/* Callback for delay:
+ Get the value of the toggle button and set the delay option.
+*/
static void
-screenshot_delay_spinner_changed(GtkWidget * spinner, PluginData *pd)
+screenshot_delay_spinner_changed(GtkWidget *spinner, PluginData *pd)
{
pd->sd->screenshot_delay =
gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinner));
}
+
+
+/* Callback for default folder:
+ Get the value of the toggle button and set the default folder option.
+*/
static void
-cb_default_folder (GtkWidget * chooser, PluginData *pd)
+cb_default_folder (GtkWidget *chooser, PluginData *pd)
{
pd->sd->screenshot_dir =
gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
}
+
+
+/* Callback for dialog response:
+ Update the tooltips if using gtk >= 2.12.
+ Unblock the plugin contextual menu.
+ Save the options in the rc file.*/
static void
screenshot_dialog_response (GtkWidget *dlg, int reponse,
PluginData *pd)
@@ -212,23 +306,28 @@
gtk_widget_destroy (dlg);
+ /* Update tooltips according to the chosen option */
#if GTK_CHECK_VERSION(2,12,0)
if (pd->sd->whole_screen)
{
- gtk_widget_set_tooltip_text (GTK_WIDGET( pd->button ),
- _("Take a screenshot of desktop"));
+ gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
+ _("Take a screenshot of desktop"));
}
else
{
- gtk_widget_set_tooltip_text (GTK_WIDGET( pd->button ),
- _("Take a screenshot of the active window"));
+ gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
+ _("Take a screenshot of the active window"));
}
#endif
-
+
+ /* Unblock the menu and save options */
xfce_panel_plugin_unblock_menu (pd->plugin);
screenshot_write_rc_file (pd->plugin, pd);
}
+
+
+/* Properties dialog to set the plugin options */
static void
screenshot_properties_dialog (XfcePanelPlugin *plugin, PluginData *pd)
{
@@ -237,7 +336,9 @@
GtkWidget *save_button, *desktop_button, *active_window_button;
GtkWidget *dir_chooser, *default_save_label, *delay_label;
GtkWidget *screenshot_delay_spinner;
-
+
+ /* Block the menu to prevent the user from launching several dialogs at
+ the same time */
xfce_panel_plugin_block_menu (plugin);
/* Create the dialog */
@@ -287,7 +388,7 @@
pd);
active_window_button =
- gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (desktop_button) ),
+ gtk_radio_button_new_with_mnemonic (gtk_radio_button_get_group (GTK_RADIO_BUTTON (desktop_button)),
_("Take a screenshot of the active window"));
gtk_widget_show (active_window_button);
gtk_box_pack_start (GTK_BOX (modes_box), active_window_button, FALSE, FALSE, 0);
@@ -318,8 +419,8 @@
/* Default save location */
default_save_label = gtk_label_new ( "" );
- gtk_label_set_markup ( GTK_LABEL (default_save_label),
- _("<span weight=\"bold\" stretch=\"semiexpanded\">Default save location</span>"));
+ gtk_label_set_markup (GTK_LABEL (default_save_label),
+ _("<span weight=\"bold\" stretch=\"semiexpanded\">Default save location</span>"));
gtk_misc_set_alignment (GTK_MISC (default_save_label), 0, 0);
gtk_widget_show (default_save_label);
gtk_container_add (GTK_CONTAINER (options_box), default_save_label);
@@ -343,29 +444,33 @@
gtk_container_add (GTK_CONTAINER (options_box), delay_label);
delay_box = gtk_hbox_new(FALSE, 8);
- gtk_widget_show(delay_box);
+ gtk_widget_show (delay_box);
gtk_box_pack_start (GTK_BOX (options_box), delay_box, FALSE, FALSE, 0);
screenshot_delay_spinner = gtk_spin_button_new_with_range(0.0, 60.0, 1.0);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON( screenshot_delay_spinner ),
- pd->sd->screenshot_delay);
- gtk_widget_show(screenshot_delay_spinner);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (screenshot_delay_spinner),
+ pd->sd->screenshot_delay);
+ gtk_widget_show (screenshot_delay_spinner);
gtk_box_pack_start (GTK_BOX (delay_box), screenshot_delay_spinner, FALSE,
FALSE, 0);
label2 = gtk_label_new_with_mnemonic(_("seconds"));
- gtk_widget_show(label2);
+ gtk_widget_show (label2);
gtk_box_pack_start (GTK_BOX (delay_box), label2, FALSE, FALSE, 0);
- g_signal_connect(screenshot_delay_spinner, "value-changed",
- G_CALLBACK(screenshot_delay_spinner_changed), pd);
+ g_signal_connect (screenshot_delay_spinner, "value-changed",
+ G_CALLBACK (screenshot_delay_spinner_changed), pd);
gtk_widget_show (dlg);
}
+
+
+/* Create the plugin button */
static void
-screenshot_construct (XfcePanelPlugin * plugin)
+screenshot_construct (XfcePanelPlugin *plugin)
{
+ /* Initialise the data structs */
PluginData *pd = g_new0 (PluginData, 1);
ScreenshotData *sd = g_new0 (ScreenshotData, 1);
@@ -375,14 +480,17 @@
pd->plugin = plugin;
+ /* Read the options */
screenshot_read_rc_file (plugin, pd);
-
+
+ /* Create the panel button */
pd->button = xfce_create_panel_button ();
pd->image = gtk_image_new ();
gtk_container_add (GTK_CONTAINER (pd->button), GTK_WIDGET (pd->image));
+ /* Set the tooltips if available */
#if GTK_CHECK_VERSION(2,12,0)
if ( pd->sd->whole_screen )
{
@@ -395,12 +503,13 @@
_("Take a screenshot of the active window"));
}
#endif
-
+
gtk_widget_show_all (pd->button);
gtk_container_add (GTK_CONTAINER (plugin), pd->button);
xfce_panel_plugin_add_action_widget (plugin, pd->button);
-
+
+ /* Set the callbacks */
g_signal_connect (pd->button, "clicked",
G_CALLBACK (button_clicked), pd);
Modified: xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.c 2008-08-18 23:18:34 UTC (rev 5277)
+++ xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.c 2008-08-19 10:58:54 UTC (rev 5278)
@@ -23,7 +23,14 @@
static gchar *generate_filename_for_uri(char *uri);
static Window find_toplevel_window (Window xid);
+
+
/* 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.
+Window: the X identifier of the window
+Returns: the X identifier of the toplevel window containing Window*/
static Window
find_toplevel_window (Window xid)
{
@@ -48,6 +55,12 @@
}
+
+/* Generates filename Screenshot-n.png where n is the first integer greater than
+0 so that Screenshot-n.jpg does not exist in the folder whose URI is *uri.
+*uri: the uri of the folder for which the filename should be generated.
+returns: a filename verifying the above conditions or NULL if *uri == NULL.
+*/
static gchar *generate_filename_for_uri(char *uri)
{
gchar *file_name;
@@ -58,27 +71,37 @@
return NULL;
}
- file_name = g_strdup ( _("Screenshot.png") );
-
- if( g_access (g_build_filename (uri, file_name, NULL), F_OK ) != 0 )
+ file_name = g_strdup (_("Screenshot.png"));
+
+ /* If the plain filename matches the condition, go for it. */
+ if (g_access (g_build_filename (uri, file_name, NULL), F_OK) != 0)
{
return file_name;
}
-
+
+ /* Else, we find the first n that matches the condition */
do
{
i++;
g_free (file_name);
- file_name = g_strdup_printf ( _("Screenshot-%d.png"), i);
+ file_name = g_strdup_printf (_("Screenshot-%d.png"), i);
}
- while( g_access (g_build_filename (uri, file_name, NULL), F_OK ) == 0 );
+ while (g_access (g_build_filename (uri, file_name, NULL), F_OK) == 0);
return file_name;
}
+
+
/* Public */
-GdkPixbuf *take_screenshot (ScreenshotData * sd)
+
+
+/* Takes the screenshot with the options given in sd.
+*sd: a ScreenshotData struct.
+returns: the screenshot in a *GdkPixbuf.
+*/
+GdkPixbuf *take_screenshot (ScreenshotData *sd)
{
GdkPixbuf *screenshot;
GdkWindow *window;
@@ -86,35 +109,44 @@
gint width;
gint height;
+ /* gdk_get_default_root_window (), needs_unref enables us to unref *window
+ only if a non default window has been grabbed */
gboolean needs_unref = TRUE;
+ /* Get the screen on which the screenshot should be taken */
screen = gdk_screen_get_default ();
-
+
+ /* Get the window/desktop we want to screenshot*/
if (sd->whole_screen)
{
- window = gdk_get_default_root_window();
+ window = gdk_get_default_root_window ();
needs_unref = FALSE;
}
else
{
window = gdk_screen_get_active_window (screen);
-
+
+ /* If we are supposed to take a screenshot of the active window, and if
+ the active window is the desktop background, grab the whole screen.*/
if (gdk_window_get_type_hint (window) == GDK_WINDOW_TYPE_HINT_DESKTOP)
{
- window = gdk_get_default_root_window();
+ window = gdk_get_default_root_window ();
needs_unref = FALSE;
}
else
{
window =
- gdk_window_foreign_new (find_toplevel_window (GDK_WINDOW_XID(window)));
+ gdk_window_foreign_new (find_toplevel_window (GDK_WINDOW_XID (window)));
}
}
- sleep(sd->screenshot_delay);
+ /* wait for n=delay seconds */
+ sleep (sd->screenshot_delay);
+ /* get the size of the part of the screen we want to screenshot */
gdk_drawable_get_size(window, &width, &height);
-
+
+ /* get the screenshot */
screenshot = gdk_pixbuf_get_from_drawable (NULL,
window,
NULL, 0, 0, 0, 0,
@@ -126,7 +158,12 @@
return screenshot;
}
-void save_screenshot (GdkPixbuf * screenshot, ScreenshotData * sd)
+
+
+/* Saves the screenshot according to the options in sd.
+*screenshot: a GdkPixbuf containing our screenshot
+*sd: a ScreenshotData struct containing the save options.*/
+void save_screenshot (GdkPixbuf *screenshot, ScreenshotData *sd)
{
GdkPixbuf * thumbnail;
gchar * filename = NULL;
@@ -134,7 +171,7 @@
GtkWidget * chooser;
gint dialog_response;
- filename = generate_filename_for_uri ( sd->screenshot_dir );
+ filename = generate_filename_for_uri (sd->screenshot_dir);
if (sd->show_save_dialog)
{
Modified: xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.h
===================================================================
--- xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.h 2008-08-18 23:18:34 UTC (rev 5277)
+++ xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.h 2008-08-19 10:58:54 UTC (rev 5278)
@@ -29,6 +29,7 @@
#include <unistd.h>
+/* Struct to store the screenshot options */
typedef struct
{
gint whole_screen;
@@ -39,5 +40,5 @@
}
ScreenshotData;
-GdkPixbuf *take_screenshot (ScreenshotData * sd);
-void save_screenshot (GdkPixbuf * screenshot, ScreenshotData * sd);
+GdkPixbuf *take_screenshot (ScreenshotData *sd);
+void save_screenshot (GdkPixbuf *screenshot, ScreenshotData *sd);
More information about the Goodies-commits
mailing list