[nautilus] Add ability to set wallpaper from image files
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Add ability to set wallpaper from image files
- Date: Thu, 16 Aug 2012 02:04:33 +0000 (UTC)
commit 5a00bdac7c2d1b3244fa35998fe72302aef91340
Author: William Jon McCann <jmccann redhat com>
Date: Wed Aug 15 18:17:29 2012 -0400
Add ability to set wallpaper from image files
http://bugzilla.gnome.org/show_bug.cgi?id=547420
src/nautilus-actions.h | 1 +
src/nautilus-directory-view-ui.xml | 1 +
src/nautilus-view.c | 128 +++++++++++++++++++++++++++++++++++-
3 files changed, 129 insertions(+), 1 deletions(-)
---
diff --git a/src/nautilus-actions.h b/src/nautilus-actions.h
index ce452c9..d642dc0 100644
--- a/src/nautilus-actions.h
+++ b/src/nautilus-actions.h
@@ -84,6 +84,7 @@
#define NAUTILUS_ACTION_RENAME "Rename"
#define NAUTILUS_ACTION_DUPLICATE "Duplicate"
#define NAUTILUS_ACTION_CREATE_LINK "Create Link"
+#define NAUTILUS_ACTION_SET_AS_WALLPAPER "Set As Wallpaper"
#define NAUTILUS_ACTION_SELECT_ALL "Select All"
#define NAUTILUS_ACTION_INVERT_SELECTION "Invert Selection"
#define NAUTILUS_ACTION_SELECT_PATTERN "Select Pattern"
diff --git a/src/nautilus-directory-view-ui.xml b/src/nautilus-directory-view-ui.xml
index 5787936..e7ccf6f 100644
--- a/src/nautilus-directory-view-ui.xml
+++ b/src/nautilus-directory-view-ui.xml
@@ -110,6 +110,7 @@
<menuitem name="Copy To" action="Copy To"/>
<menuitem name="Properties" action="Properties"/>
<menuitem name="Rename" action="Rename"/>
+ <menuitem name="Set As Wallpaper" action="Set As Wallpaper"/>
</placeholder>
<separator name="Dangerous separator"/>
<placeholder name="Dangerous File Actions">
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index ca17e74..94019a8 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -84,6 +84,9 @@
#include <libnautilus-private/nautilus-icon-names.h>
#include <libnautilus-private/nautilus-file-undo-manager.h>
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <gdesktop-enums.h>
+
#define DEBUG_FLAG NAUTILUS_DEBUG_DIRECTORY_VIEW
#include <libnautilus-private/nautilus-debug.h>
@@ -3336,7 +3339,6 @@ remove_not_really_moved_files (gpointer key,
return TRUE;
}
-
/* When this function is invoked, the file operation is over, but all
* the icons may not have been added to the directory view yet, so
* we can't select them yet.
@@ -6495,6 +6497,117 @@ action_rename_select_all_callback (GtkAction *action,
real_action_rename (NAUTILUS_VIEW (callback_data), TRUE);
}
+#define BG_KEY_DRAW_BACKGROUND "draw-background"
+#define BG_KEY_PRIMARY_COLOR "primary-color"
+#define BG_KEY_SECONDARY_COLOR "secondary-color"
+#define BG_KEY_COLOR_TYPE "color-shading-type"
+#define BG_KEY_PICTURE_PLACEMENT "picture-options"
+#define BG_KEY_PICTURE_URI "picture-uri"
+
+static void
+set_uri_as_wallpaper (const char *uri)
+{
+ GSettings *settings;
+
+ settings = gnome_background_preferences;
+
+ g_settings_delay (settings);
+
+ if (uri == NULL)
+ uri = "";
+
+ g_settings_set_boolean (settings, BG_KEY_DRAW_BACKGROUND, TRUE);
+ g_settings_set_string (settings, BG_KEY_PICTURE_URI, uri);
+ g_settings_set_string (settings, BG_KEY_PRIMARY_COLOR, "#000000");
+ g_settings_set_string (settings, BG_KEY_SECONDARY_COLOR, "#000000");
+ g_settings_set_enum (settings, BG_KEY_COLOR_TYPE, G_DESKTOP_BACKGROUND_SHADING_SOLID);
+ g_settings_set_enum (settings, BG_KEY_PICTURE_PLACEMENT, G_DESKTOP_BACKGROUND_STYLE_ZOOM);
+
+ /* Apply changes atomically. */
+ g_settings_apply (settings);
+}
+
+static void
+wallpaper_copy_done_callback (GHashTable *debuting_files,
+ gboolean success,
+ gpointer data)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init (&iter, debuting_files);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ char *uri;
+ uri = g_file_get_uri (G_FILE (key));
+ set_uri_as_wallpaper (uri);
+ g_free (uri);
+ break;
+ }
+}
+
+static gboolean
+can_set_wallpaper (GList *selection)
+{
+ NautilusFile *file;
+
+ if (g_list_length (selection) != 1) {
+ return FALSE;
+ }
+
+ file = NAUTILUS_FILE (selection->data);
+ if (!nautilus_file_is_mime_type (file, "image/*")) {
+ return FALSE;
+ }
+
+ /* FIXME: check file size? */
+
+ return TRUE;
+}
+
+static void
+action_set_as_wallpaper_callback (GtkAction *action,
+ NautilusView *view)
+{
+ GList *selection;
+
+ /* Copy the item to Pictures/Wallpaper since it may be
+ remote. Then set it as the current wallpaper. */
+
+ g_assert (NAUTILUS_IS_VIEW (view));
+
+ selection = nautilus_view_get_selection (view);
+
+ if (can_set_wallpaper (selection)
+ && selection_not_empty_in_menu_callback (view, selection)) {
+ NautilusFile *file;
+ char *target_uri;
+ GList *uris;
+ GFile *parent;
+ GFile *target;
+
+ file = NAUTILUS_FILE (selection->data);
+
+ parent = g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_PICTURES));
+ target = g_file_get_child (parent, "Wallpapers");
+ g_object_unref (parent);
+ g_file_make_directory_with_parents (target, NULL, NULL);
+ target_uri = g_file_get_uri (target);
+ g_object_unref (target);
+ uris = g_list_prepend (NULL, nautilus_file_get_uri (file));
+ nautilus_file_operations_copy_move (uris,
+ NULL,
+ target_uri,
+ GDK_ACTION_COPY,
+ GTK_WIDGET (view),
+ wallpaper_copy_done_callback,
+ NULL);
+ g_free (target_uri);
+ g_list_free_full (uris, g_free);
+ }
+
+ nautilus_file_list_free (selection);
+}
+
static void
file_mount_callback (NautilusFile *file,
GFile *result_location,
@@ -7391,6 +7504,10 @@ static const GtkActionEntry directory_view_entries[] = {
/* label, accelerator */ N_("Rena_me..."), "F2",
/* tooltip */ N_("Rename selected item"),
G_CALLBACK (action_rename_callback) },
+ /* name, stock id */ { "Set As Wallpaper", NULL,
+ /* label, accelerator */ N_("Set as Wallpaper"), NULL,
+ /* tooltip */ N_("Make item the wallpaper"),
+ G_CALLBACK (action_set_as_wallpaper_callback) },
/* name, stock id */ { "RenameSelectAll", NULL,
/* label, accelerator */ "RenameSelectAll", "<shift>F2",
/* tooltip */ NULL,
@@ -8673,6 +8790,15 @@ real_update_menus (NautilusView *view)
gtk_action_set_visible (action, !selection_contains_recent);
action = gtk_action_group_get_action (view->details->dir_action_group,
+ NAUTILUS_ACTION_SET_AS_WALLPAPER);
+ /* rename sensitivity depending on selection */
+ if (can_set_wallpaper (selection)) {
+ gtk_action_set_visible (action, TRUE);
+ } else {
+ gtk_action_set_visible (action, FALSE);
+ }
+
+ action = gtk_action_group_get_action (view->details->dir_action_group,
NAUTILUS_ACTION_NEW_FOLDER);
gtk_action_set_sensitive (action, can_create_files);
gtk_action_set_visible (action, !selection_contains_recent);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]