Commit 1d72ac04 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

[desktop_background] added ability to reset or open the preferences

after setting a desktop background an info-bar is displayd at the
bottom of the window to allow the user to reset the previous
background or to open the background preferences.
parent 43b6f7d8
......@@ -11,7 +11,7 @@ libdesktop_background_la_SOURCES = \
libdesktop_background_la_CFLAGS = $(GTHUMB_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
libdesktop_background_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
libdesktop_background_la_LIBADD = $(GTHUMB_LIBS)
libdesktop_background_la_LIBADD = $(GTHUMB_LIBS) ../image_viewer/libimage_viewer.la
libdesktop_background_la_DEPENDENCIES = $(top_builddir)/gthumb/gthumb$(EXEEXT)
extensioninidir = $(extensiondir)
......
......@@ -24,21 +24,248 @@
#include <config.h>
#include <glib/gi18n.h>
#include <gthumb.h>
#include <extensions/image_viewer/gth-image-viewer-page.h>
typedef struct {
GthBrowser *browser;
GFile *old_file;
GFile *new_file;
gulong response_id;
} WallpaperData;
static GFile *
get_wallpaper_file_n (int n)
{
char *name;
char *filename;
GFile *file;
name = g_strdup_printf ("wallpaper%d.jpeg", n);
gth_user_dir_make_dir_for_file (GTH_DIR_DATA, GTHUMB_DIR, name, NULL);
filename = gth_user_dir_get_file (GTH_DIR_DATA, GTHUMB_DIR, name, NULL);
file = g_file_new_for_path (filename);
g_free (filename);
g_free (name);
return file;
}
static GFile *
get_wallpaper_file (void)
{
GFile *wallpaper_file;
wallpaper_file = get_wallpaper_file_n (1);
if (g_file_query_exists (wallpaper_file, NULL)) {
/* Use a new filename to force an update. */
g_object_unref (wallpaper_file);
wallpaper_file = get_wallpaper_file_n (2);
if (g_file_query_exists (wallpaper_file, NULL))
g_file_delete (wallpaper_file, NULL, NULL);
}
return wallpaper_file;
}
static WallpaperData *
wallpaper_data_new (GthBrowser *browser)
{
WallpaperData *wdata;
char *path;
wdata = g_new0 (WallpaperData, 1);
wdata->browser = browser;
path = eel_gconf_get_string ("/desktop/gnome/background/picture_filename", NULL);
if (path != NULL) {
wdata->old_file = g_file_new_for_path (path);
g_free (path);
}
wdata->new_file = get_wallpaper_file ();
return wdata;
}
static void
wallpaper_data_free (WallpaperData *wdata)
{
g_signal_handler_disconnect (gth_browser_get_infobar (wdata->browser), wdata->response_id);
_g_object_unref (wdata->old_file);
_g_object_unref (wdata->new_file);
g_free (wdata);
}
enum {
_RESPONSE_PREFERENCES = 1,
_RESPONSE_UNDO
};
static void
set_wallpaper_file (GFile *file)
{
char *path;
path = g_file_get_path (file);
if (path != NULL)
eel_gconf_set_string ("/desktop/gnome/background/picture_filename", path);
g_free (path);
}
static void
infobar_response_cb (GtkInfoBar *info_bar,
int response_id,
gpointer user_data)
{
WallpaperData *wdata = user_data;
GError *error = NULL;
g_return_if_fail (GTH_IS_BROWSER (wdata->browser));
switch (response_id) {
case _RESPONSE_PREFERENCES:
if (! g_spawn_command_line_async ("gnome-appearance-properties --show-page=background", &error))
_gtk_error_dialog_from_gerror_run (GTK_WINDOW (wdata->browser), _("Could not show the desktop background properties"), &error);
break;
case _RESPONSE_UNDO:
if (wdata->old_file != NULL)
set_wallpaper_file (wdata->old_file);
break;
}
gtk_widget_hide (GTK_WIDGET (info_bar));
wallpaper_data_free (wdata);
}
static void
wallpaper_data_set (WallpaperData *wdata)
{
GtkWidget *infobar;
set_wallpaper_file (wdata->new_file);
infobar = gth_browser_get_infobar (wdata->browser);
gth_info_bar_set_icon (GTH_INFO_BAR (infobar), GTK_STOCK_DIALOG_INFO);
{
char *name;
char *msg;
name = _g_file_get_display_name (wdata->new_file);
msg = g_strdup_printf ("The image \"%s\" has been set as desktop background", name);
gth_info_bar_set_primary_text (GTH_INFO_BAR (infobar), msg);
g_free (msg);
g_free (name);
}
_gtk_info_bar_clear_action_area (GTK_INFO_BAR (infobar));
gtk_orientable_set_orientation (GTK_ORIENTABLE (gtk_info_bar_get_action_area (GTK_INFO_BAR (infobar))), GTK_ORIENTATION_HORIZONTAL);
gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
gtk_info_bar_add_buttons (GTK_INFO_BAR (infobar),
GTK_STOCK_PREFERENCES, _RESPONSE_PREFERENCES,
GTK_STOCK_UNDO, _RESPONSE_UNDO,
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
NULL);
gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (infobar),
_RESPONSE_UNDO,
wdata->old_file != NULL);
wdata->response_id = g_signal_connect (infobar,
"response",
G_CALLBACK (infobar_response_cb),
wdata);
gtk_widget_show (infobar);
}
static void
wallpaper_save_ready_cb (GthFileData *a,
GError *error,
gpointer user_data)
{
WallpaperData *wdata = user_data;
if (error != NULL) {
_gtk_error_dialog_from_gerror_run (GTK_WINDOW (wdata->browser), _("Could not set the desktop background"), &error);
wallpaper_data_free (wdata);
return;
}
wallpaper_data_set (wdata);
}
static void
copy_wallpaper_ready_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
WallpaperData *wdata = user_data;
GError *error = NULL;
if (! g_file_copy_finish (G_FILE (source_object), res, &error)) {
_gtk_error_dialog_from_gerror_run (GTK_WINDOW (wdata->browser), _("Could not set the desktop background"), &error);
wallpaper_data_free (wdata);
return;
}
wallpaper_data_set (wdata);
}
void
gth_browser_activate_action_tool_desktop_background (GtkAction *action,
GthBrowser *browser)
{
GList *items;
GList *file_list;
GthFileData *file_data;
char *path;
GError *error = NULL;
WallpaperData *wdata;
gboolean saving_wallpaper = FALSE;
GthFileData *file_data;
GList *items;
GList *file_list;
wdata = wallpaper_data_new (browser);
if (gth_main_extension_is_active ("image_viewer") && gth_browser_get_file_modified (browser)) {
GtkWidget *viewer_page;
viewer_page = gth_browser_get_viewer_page (browser);
if (viewer_page != NULL) {
GdkPixbuf *pixbuf;
pixbuf = g_object_ref (gth_image_viewer_page_get_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page)));
file_data = gth_file_data_new (wdata->new_file, NULL);
_gdk_pixbuf_save_async (pixbuf,
file_data,
"image/jpeg",
TRUE,
wallpaper_save_ready_cb,
wdata);
saving_wallpaper = TRUE;
g_object_unref (pixbuf);
}
}
if (saving_wallpaper)
return;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
if (file_list == NULL)
return;
......@@ -46,14 +273,22 @@ gth_browser_activate_action_tool_desktop_background (GtkAction *action,
if (file_data == NULL)
return;
path = g_file_get_path (file_data->file);
if (path != NULL)
eel_gconf_set_string ("/desktop/gnome/background/picture_filename", path);
if (g_file_is_native (file_data->file)) {
_g_object_unref (wdata->new_file);
wdata->new_file = g_file_dup (file_data->file);
wallpaper_data_set (wdata);
}
else
g_file_copy_async (file_data->file,
wdata->new_file,
G_FILE_COPY_OVERWRITE,
G_PRIORITY_DEFAULT,
NULL,
NULL,
NULL,
copy_wallpaper_ready_cb,
wdata);
if (! g_spawn_command_line_async ("gnome-appearance-properties --show-page=background", &error))
_gtk_error_dialog_from_gerror_run (GTK_WINDOW (browser), _("Could not show the desktop background properties"), &error);
g_free (path);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
......@@ -10,3 +10,4 @@ Category=List-Tool
[Loader]
Type=module
File=%LIBRARY%
After=image_viewer
......@@ -73,6 +73,7 @@ PUBLIC_HEADER_FILES = \
gth-image-selector.h \
gth-image-viewer.h \
gth-image-viewer-tool.h \
gth-info-bar.h \
gth-location-chooser.h \
gth-main.h \
gth-metadata.h \
......@@ -130,6 +131,7 @@ PRIVATE_HEADER_FILES = \
dlg-sort-order.h \
gth-window-actions-callbacks.h \
gth-window-actions-entries.h \
main-migrate.h \
$(NULL)
gthumb_SOURCES = \
......@@ -186,6 +188,7 @@ gthumb_SOURCES = \
gth-image-selector.c \
gth-image-viewer.c \
gth-image-viewer-tool.c \
gth-info-bar.c \
gth-location-chooser.c \
gth-main.c \
gth-main-default-hooks.c \
......@@ -231,6 +234,7 @@ gthumb_SOURCES = \
gtk-utils.c \
gvaluehash.c \
main.c \
main-migrate-catalogs.c \
pixbuf-cache.c \
pixbuf-io.c \
pixbuf-utils.c \
......
......@@ -42,6 +42,7 @@
#include "gth-filterbar.h"
#include "gth-folder-tree.h"
#include "gth-icon-cache.h"
#include "gth-info-bar.h"
#include "gth-image-preloader.h"
#include "gth-location-chooser.h"
#include "gth-main.h"
......@@ -87,6 +88,7 @@ struct _GthBrowserPrivateData {
GtkUIManager *ui;
GtkActionGroup *actions;
GtkWidget *infobar;
GtkWidget *statusbar;
GtkWidget *browser_toolbar;
GtkWidget *browser_container;
......@@ -1703,6 +1705,14 @@ mount_volume_ready_cb (GObject *source_object,
}
static void
_gth_browser_hide_infobar (GthBrowser *browser)
{
if (gtk_widget_get_visible (browser->priv->infobar))
gtk_info_bar_response (GTK_INFO_BAR (browser->priv->infobar), GTK_RESPONSE_CLOSE);
}
static void
_gth_browser_load (GthBrowser *browser,
GFile *location,
......@@ -1713,6 +1723,9 @@ _gth_browser_load (GthBrowser *browser,
LoadData *load_data;
GFile *entry_point;
if (! automatic)
_gth_browser_hide_infobar (browser);
switch (action) {
case GTH_ACTION_GO_TO:
case GTH_ACTION_GO_INTO:
......@@ -2157,6 +2170,7 @@ _gth_browser_real_set_current_page (GthWindow *window,
gtk_widget_grab_focus (gth_browser_get_file_list_view (browser));
else if (page == GTH_BROWSER_PAGE_VIEWER)
_gth_browser_make_file_visible (browser, browser->priv->current_file);
_gth_browser_hide_infobar (browser);
gth_hook_invoke ("gth-browser-set-current-page", browser);
......@@ -3902,6 +3916,11 @@ _gth_browser_construct (GthBrowser *browser)
gth_window_attach_toolbar (GTH_WINDOW (browser), GTH_BROWSER_PAGE_BROWSER, browser->priv->browser_toolbar);
add_browser_toolbar_menu_buttons (browser);
/* infobar */
browser->priv->infobar = gth_info_bar_new (NULL, NULL, NULL);
gth_window_attach (GTH_WINDOW (browser), browser->priv->infobar, GTH_WINDOW_INFOBAR);
/* statusbar */
browser->priv->statusbar = gth_statusbar_new ();
......@@ -4395,6 +4414,13 @@ gth_browser_get_browser_toolbar (GthBrowser *browser)
}
GtkWidget *
gth_browser_get_infobar (GthBrowser *browser)
{
return browser->priv->infobar;
}
GtkWidget *
gth_browser_get_statusbar (GthBrowser *browser)
{
......@@ -5209,6 +5235,8 @@ gth_browser_load_file (GthBrowser *browser,
{
LoadFileData *data;
_gth_browser_hide_infobar (browser);
data = load_file_data_new (browser, file_data, view);
if (browser->priv->load_file_timeout != 0) {
......
......@@ -102,6 +102,7 @@ GtkWidget * gth_browser_get_dialog (GthBrowser *browser,
GtkUIManager * gth_browser_get_ui_manager (GthBrowser *browser);
GthIconCache * gth_browser_get_menu_icon_cache (GthBrowser *browser);
GtkWidget * gth_browser_get_browser_toolbar (GthBrowser *browser);
GtkWidget * gth_browser_get_infobar (GthBrowser *browser);
GtkWidget * gth_browser_get_statusbar (GthBrowser *browser);
GtkWidget * gth_browser_get_file_list (GthBrowser *browser);
GtkWidget * gth_browser_get_file_list_view (GthBrowser *browser);
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* GThumb
*
* Copyright (C) 2009 The Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <gtk/gtk.h>
#include "gth-info-bar.h"
static gpointer parent_class = NULL;
struct _GthInfoBarPrivate {
GtkWidget *icon_image;
GtkWidget *primary_text_label;
GtkWidget *secondary_text_label;
};
static void
gth_info_bar_class_init (GthInfoBarClass *klass)
{
parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GthInfoBarPrivate));
}
static void
gth_info_bar_init (GthInfoBar *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_INFO_BAR, GthInfoBarPrivate);
}
GType
gth_info_bar_get_type (void)
{
static GType type = 0;
if (! type) {
GTypeInfo type_info = {
sizeof (GthInfoBarClass),
NULL,
NULL,
(GClassInitFunc) gth_info_bar_class_init,
NULL,
NULL,
sizeof (GthInfoBar),
0,
(GInstanceInitFunc) gth_info_bar_init
};
type = g_type_register_static (GTK_TYPE_INFO_BAR,
"GthEmbeddedEditorDialog",
&type_info,
0);
}
return type;
}
static void
gth_info_bar_construct (GthInfoBar *self)
{
GtkWidget *hbox_content;
GtkWidget *image;
GtkWidget *vbox;
GtkWidget *primary_label;
GtkWidget *secondary_label;
GtkWidget *area;
hbox_content = gtk_hbox_new (FALSE, 8);
gtk_widget_show (hbox_content);
self->priv->icon_image = image = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
vbox = gtk_vbox_new (FALSE, 6);
gtk_widget_show (vbox);
gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);
self->priv->primary_text_label = primary_label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (primary_label, GTK_CAN_FOCUS);
gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
gtk_misc_set_padding (GTK_MISC (primary_label), 0, 0);
gtk_label_set_ellipsize (GTK_LABEL (primary_label), PANGO_ELLIPSIZE_MIDDLE);
gtk_misc_set_alignment (GTK_MISC (primary_label), 0, 0.5);
gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
self->priv->secondary_text_label = secondary_label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (secondary_label, GTK_CAN_FOCUS);
gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
gtk_misc_set_padding (GTK_MISC (secondary_label), 0, 0);
gtk_label_set_ellipsize (GTK_LABEL (secondary_label), PANGO_ELLIPSIZE_END);
gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5);
gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
area = gtk_info_bar_get_action_area (GTK_INFO_BAR (self));
gtk_container_set_border_width (GTK_CONTAINER (self), 0);
gtk_box_set_homogeneous (GTK_BOX (area), FALSE);
gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_HORIZONTAL);
area = gtk_info_bar_get_content_area (GTK_INFO_BAR (self));
gtk_container_set_border_width (GTK_CONTAINER (self), 0);
gtk_container_add (GTK_CONTAINER (area), hbox_content);
gtk_widget_set_name (GTK_WIDGET (self), "GthInfoBar");
gtk_info_bar_set_message_type (GTK_INFO_BAR (self), GTK_MESSAGE_OTHER);
gtk_container_set_border_width (GTK_CONTAINER (self), 0);
}
GtkWidget *
gth_info_bar_new (const char *icon_stock_id,
const char *primary_text,
const char *secondary_text)
{
GthInfoBar *self;
self = g_object_new (GTH_TYPE_INFO_BAR, NULL);
gth_info_bar_construct (self);
gth_info_bar_set_icon (self, icon_stock_id);
gth_info_bar_set_primary_text (self, primary_text);
gth_info_bar_set_secondary_text (self, secondary_text);
return (GtkWidget *) self;
}
void
gth_info_bar_set_icon (GthInfoBar *self,
const char *icon_stock_id)
{
if (icon_stock_id == NULL) {
gtk_widget_hide (self->priv->icon_image);
return;
}
gtk_image_set_from_stock (GTK_IMAGE (self->priv->icon_image), icon_stock_id, GTK_ICON_SIZE_BUTTON);
gtk_widget_show (self->priv->icon_image);
}
void
gth_info_bar_set_gicon (GthInfoBar *self,
GIcon *icon)
{
if (icon == NULL) {
gtk_widget_hide (self->priv->icon_image);
return;
}
gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon_image), icon, GTK_ICON_SIZE_BUTTON);
gtk_widget_show (self->priv->icon_image);
}
void
gth_info_bar_set_primary_text (GthInfoBar *self,
const char *text)
{
char *escaped;
char *markup;
if (text == NULL) {
gtk_widget_hide (self->priv->primary_text_label);
return;
}
escaped = g_markup_escape_text (text, -1);
markup = g_strdup_printf ("<b>%s</b>", escaped);
gtk_label_set_markup (GTK_LABEL (self->priv->primary_text_label), markup);
gtk_widget_show (self->priv->primary_text_label);
g_free (markup);
g_free (escaped);