summaryrefslogtreecommitdiff
path: root/libnautilus-private
diff options
context:
space:
mode:
authorDave Camp <dave@ximian.com>2002-10-31 22:38:46 +0000
committerDave Camp <campd@src.gnome.org>2002-10-31 22:38:46 +0000
commitcd6b5059951cee4fb1102dfe392c6719943798ed (patch)
tree7af3ecd96c9358c96761b3896677ba307f8aa4cb /libnautilus-private
parent56c379f59f40fa53de6c5ecaf72752fbface290b (diff)
downloadnautilus-cd6b5059951cee4fb1102dfe392c6719943798ed.tar.gz
Set the background globally by default. On a right-drag from the property
2002-10-31 Dave Camp <dave@ximian.com> * libnautilus-private/nautilus-directory-background.c: (nautilus_file_background_get_default_settings), (nautilus_file_background_is_set), (background_changed_callback), (background_reset_callback): * libnautilus-private/nautilus-dnd.c: (nautilus_drag_drop_background_ask): * libnautilus-private/nautilus-dnd.h: * libnautilus-private/nautilus-global-preferences.h: * libnautilus-private/nautilus-icon-dnd.c: (get_background_drag_action), (receive_dropped_color), (receive_dropped_tile_image), (nautilus_icon_container_receive_dropped_icons), (drag_data_received_callback): Set the background globally by default. On a right-drag from the property dialog, pop up a context menu asking to set it globally or for that directory. * libnautilus-private/apps_nautilus_preferences.schemas: * src/nautilus-information-panel.c: (nautilus_information_panel_init), (nautilus_information_panel_finalize), (information_panel_has_background), (nautilus_information_panel_create_context_menu), (nautilus_information_panel_read_defaults), (nautilus_information_panel_theme_changed), (receive_dropped_uri_list), (receive_dropped_color), (nautilus_information_panel_drag_data_received), (background_settings_changed_callback), (background_reset_callback), (nautilus_information_panel_update_appearance): Take the default background from gconf, handle global vs. per-directory backgrounds. * nautilus-property-browser.c: (element_clicked_callback): Add ASK to the list of actions.
Diffstat (limited to 'libnautilus-private')
-rw-r--r--libnautilus-private/apps_nautilus_preferences.schemas36
-rw-r--r--libnautilus-private/nautilus-directory-background.c156
-rw-r--r--libnautilus-private/nautilus-dnd.c53
-rw-r--r--libnautilus-private/nautilus-dnd.h6
-rw-r--r--libnautilus-private/nautilus-global-preferences.h5
-rw-r--r--libnautilus-private/nautilus-icon-dnd.c59
6 files changed, 226 insertions, 89 deletions
diff --git a/libnautilus-private/apps_nautilus_preferences.schemas b/libnautilus-private/apps_nautilus_preferences.schemas
index 23b537ebb..ca775c497 100644
--- a/libnautilus-private/apps_nautilus_preferences.schemas
+++ b/libnautilus-private/apps_nautilus_preferences.schemas
@@ -397,6 +397,42 @@
</locale>
</schema>
+
+ <schema>
+ <key>/schemas/apps/nautilus/preferences/side_pane_background_set</key>
+ <applyto>/apps/nautilus/preferences/side_pane_background_set</applyto>
+ <owner>nautilus</owner>
+ <type>bool</type>
+ <default>false</default>
+ <locale name="C">
+ <short>Custom Side Pane Background Set</short>
+ <long>Whether a custom default side pane background has been set.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/nautilus/preferences/side_pane_background_color</key>
+ <applyto>/apps/nautilus/preferences/side_pane_background_color</applyto>
+ <owner>nautilus</owner>
+ <type>string</type>
+ <default>#ffffff</default>
+ <locale name="C">
+ <short>Default Side Pane Background Color</short>
+ <long>Filename for the default side pane background. Only used if side_pane_background_set is true.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/nautilus/preferences/side_pane_background_filename</key>
+ <applyto>/apps/nautilus/preferences/side_pane_background_filename</applyto>
+ <owner>nautilus</owner>
+ <type>string</type>
+ <default></default>
+ <locale name="C">
+ <short>Default Side Pane Background Filename</short>
+ <long>Filename for the default side pane background. Only used if side_pane_background_set is true.</long>
+ </locale>
+ </schema>
+
+
<!-- Icon View -->
<schema>
diff --git a/libnautilus-private/nautilus-directory-background.c b/libnautilus-private/nautilus-directory-background.c
index 22b55f4eb..7eefbe553 100644
--- a/libnautilus-private/nautilus-directory-background.c
+++ b/libnautilus-private/nautilus-directory-background.c
@@ -30,6 +30,7 @@
#include <eel/eel-gdk-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-background.h>
+#include "nautilus-dnd.h"
#include "nautilus-global-preferences.h"
#include "nautilus-metadata.h"
#include "nautilus-file-attributes.h"
@@ -44,7 +45,8 @@
#include <libbackground/preferences.h>
static void background_changed_callback (EelBackground *background,
- NautilusFile *file);
+ GdkDragAction action,
+ NautilusFile *file);
static void background_reset_callback (EelBackground *background,
NautilusFile *file);
@@ -58,11 +60,7 @@ static void nautilus_file_update_desktop_pixmaps (EelBackground *background);
static void nautilus_file_background_write_desktop_settings (char *color,
char *image,
EelBackgroundImagePlacement placement);
-
-static gboolean nautilus_file_background_matches_default_settings (
- const char* color, const char* default_color,
- const char* image, const char* default_image,
- EelBackgroundImagePlacement placement, EelBackgroundImagePlacement default_placement);
+static void nautilus_file_background_theme_changed (gpointer user_data);
static void
screen_size_changed (GdkScreen *screen, NautilusIconContainer *icon_container)
@@ -161,30 +159,17 @@ nautilus_file_background_get_default_settings (char **color,
char **image,
EelBackgroundImagePlacement *placement)
{
- static gboolean setup_autos = FALSE;
- static gboolean background_set;
- static const char *background_color;
- static const char *background_filename;
-
- if (!setup_autos) {
- setup_autos = TRUE;
- eel_preferences_add_auto_boolean
- (NAUTILUS_PREFERENCES_BACKGROUND_SET,
- &background_set);
- eel_preferences_add_auto_string
- (NAUTILUS_PREFERENCES_BACKGROUND_COLOR,
- &background_color);
- eel_preferences_add_auto_string
- (NAUTILUS_PREFERENCES_BACKGROUND_FILENAME,
- &background_filename);
- }
+ gboolean background_set;
- if (color) {
- *color = background_set ? g_strdup (background_color) : NULL;
+ background_set = eel_preferences_get_boolean
+ (NAUTILUS_PREFERENCES_BACKGROUND_SET);
+
+ if (background_set && color) {
+ *color = eel_preferences_get (NAUTILUS_PREFERENCES_BACKGROUND_COLOR);
}
-
- if (image) {
- *image = background_set ? g_strdup (background_filename) : NULL;
+
+ if (background_set && image) {
+ *image = eel_preferences_get (NAUTILUS_PREFERENCES_BACKGROUND_FILENAME);
}
if (placement) {
@@ -564,58 +549,31 @@ nautilus_file_update_desktop_pixmaps (EelBackground *background)
}
}
-static gboolean
-nautilus_file_background_matches_default_settings (
- const char* color, const char* default_color,
- const char* image, const char* default_image,
- EelBackgroundImagePlacement placement, EelBackgroundImagePlacement default_placement)
-{
- gboolean match_color;
- gboolean match_image;
-
- match_color = (eel_strcmp (color, default_color) == 0);
-
- match_image = (eel_strcmp (image, default_image) == 0) && (placement == default_placement);
- return match_color && match_image;
-}
-
/* return true if the background is not in the default state */
gboolean
nautilus_file_background_is_set (EelBackground *background)
{
char *color;
char *image;
- char *default_color;
- char *default_image;
- gboolean matches;
+ gboolean is_set;
- EelBackgroundImagePlacement placement;
- EelBackgroundImagePlacement default_placement;
-
color = eel_background_get_color (background);
image = eel_background_get_image_uri (background);
- placement = eel_background_get_image_placement (background);
-
- nautilus_file_background_get_default_settings (
- &default_color, &default_image, &default_placement);
-
- matches = nautilus_file_background_matches_default_settings (color, default_color,
- image, default_image,
- placement, default_placement);
-
+
+ is_set = (color || image);
+
g_free (color);
g_free (image);
- g_free (default_color);
- g_free (default_image);
- return !matches;
+ return is_set;
}
/* handle the background changed signal */
static void
background_changed_callback (EelBackground *background,
- NautilusFile *file)
+ GdkDragAction action,
+ NautilusFile *file)
{
char *color;
char *image;
@@ -637,16 +595,35 @@ background_changed_callback (EelBackground *background,
g_signal_handlers_block_by_func (
file, G_CALLBACK (saved_settings_changed_callback), background);
- nautilus_file_set_metadata (file,
- NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR,
- NULL,
- color);
+ if (action != NAUTILUS_DND_ACTION_SET_AS_BACKGROUND) {
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR,
+ NULL,
+ NULL);
+
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE,
+ NULL,
+ NULL);
- nautilus_file_set_metadata (file,
- NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE,
- NULL,
- image);
-
+ eel_preferences_set
+ (NAUTILUS_PREFERENCES_BACKGROUND_COLOR, color ? color : "");
+ eel_preferences_set
+ (NAUTILUS_PREFERENCES_BACKGROUND_FILENAME, image ? image : "");
+ eel_preferences_set_boolean
+ (NAUTILUS_PREFERENCES_BACKGROUND_SET, TRUE);
+ } else {
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR,
+ NULL,
+ color);
+
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE,
+ NULL,
+ image);
+ }
+
/* Unblock the handler. */
g_signal_handlers_unblock_by_func (
file, G_CALLBACK (saved_settings_changed_callback), background);
@@ -749,6 +726,9 @@ static void
background_reset_callback (EelBackground *background,
NautilusFile *file)
{
+ char *color;
+ char *image;
+
if (background_is_desktop (background)) {
nautilus_file_background_write_desktop_default_settings ();
} else {
@@ -760,16 +740,30 @@ background_reset_callback (EelBackground *background,
G_CALLBACK (saved_settings_changed_callback),
background);
- /* reset the metadata */
- nautilus_file_set_metadata (file,
- NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR,
- NULL,
- NULL);
-
- nautilus_file_set_metadata (file,
- NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE,
- NULL,
- NULL);
+ color = nautilus_file_get_metadata (file,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR,
+ NULL);
+ image = nautilus_file_get_metadata (file,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE,
+ NULL);
+ if (!color && !image) {
+ eel_preferences_set_boolean (NAUTILUS_PREFERENCES_BACKGROUND_SET,
+ FALSE);
+ } else {
+ /* reset the metadata */
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR,
+ NULL,
+ NULL);
+
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE,
+ NULL,
+ NULL);
+ }
+ g_free (color);
+ g_free (image);
+
/* Unblock the handler. */
g_signal_handlers_unblock_by_func (
file,
diff --git a/libnautilus-private/nautilus-dnd.c b/libnautilus-private/nautilus-dnd.c
index 1eb7e2dd6..f4398cec9 100644
--- a/libnautilus-private/nautilus-dnd.c
+++ b/libnautilus-private/nautilus-dnd.c
@@ -613,6 +613,59 @@ nautilus_drag_drop_action_ask (GdkDragAction actions)
return damd.chosen;
}
+GdkDragAction
+nautilus_drag_drop_background_ask (GdkDragAction actions)
+{
+ GtkWidget *menu;
+ GtkWidget *menu_item;
+ DropActionMenuData damd;
+
+ /* Create the menu and set the sensitivity of the items based on the
+ * allowed actions.
+ */
+ menu = gtk_menu_new ();
+
+ append_drop_action_menu_item (menu, _("Set as background for _all directories"),
+ NAUTILUS_DND_ACTION_SET_AS_GLOBAL_BACKGROUND,
+ (actions & NAUTILUS_DND_ACTION_SET_AS_GLOBAL_BACKGROUND) != 0,
+ &damd);
+
+ append_drop_action_menu_item (menu, _("Set as background for _this directory"),
+ NAUTILUS_DND_ACTION_SET_AS_BACKGROUND,
+ (actions & NAUTILUS_DND_ACTION_SET_AS_BACKGROUND) != 0,
+ &damd);
+
+ menu_item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ gtk_widget_show (menu_item);
+
+ menu_item = gtk_menu_item_new_with_mnemonic (_("Cancel"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ gtk_widget_show (menu_item);
+
+ damd.chosen = 0;
+ damd.loop = g_main_loop_new (NULL, FALSE);
+
+ g_signal_connect (menu, "deactivate",
+ G_CALLBACK (menu_deactivate_callback),
+ &damd);
+
+ gtk_grab_add (menu);
+
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+ NULL, NULL, 0, GDK_CURRENT_TIME);
+
+ g_main_loop_run (damd.loop);
+
+ gtk_grab_remove (menu);
+
+ g_main_loop_unref (damd.loop);
+
+ gtk_object_sink (GTK_OBJECT (menu));
+
+ return damd.chosen;
+}
+
gboolean
nautilus_drag_autoscroll_in_scroll_region (GtkWidget *widget)
{
diff --git a/libnautilus-private/nautilus-dnd.h b/libnautilus-private/nautilus-dnd.h
index 75b857d5b..54f43a8bb 100644
--- a/libnautilus-private/nautilus-dnd.h
+++ b/libnautilus-private/nautilus-dnd.h
@@ -63,7 +63,8 @@ typedef enum {
typedef enum {
NAUTILUS_DND_ACTION_FIRST = GDK_ACTION_ASK << 1,
- NAUTILUS_DND_ACTION_SET_AS_BACKGROUND = NAUTILUS_DND_ACTION_FIRST << 0
+ NAUTILUS_DND_ACTION_SET_AS_BACKGROUND = NAUTILUS_DND_ACTION_FIRST << 0,
+ NAUTILUS_DND_ACTION_SET_AS_GLOBAL_BACKGROUND = NAUTILUS_DND_ACTION_FIRST << 1
} NautilusDndAction;
/* drag&drop-related information. */
@@ -126,7 +127,10 @@ gboolean nautilus_drag_drag_data_get (GtkWidg
NautilusDragEachSelectedItemIterator each_selected_item_iterator);
int nautilus_drag_modifier_based_action (int default_action,
int non_default_action);
+
GdkDragAction nautilus_drag_drop_action_ask (GdkDragAction possible_actions);
+GdkDragAction nautilus_drag_drop_background_ask (GdkDragAction possible_actions);
+
gboolean nautilus_drag_autoscroll_in_scroll_region (GtkWidget *widget);
void nautilus_drag_autoscroll_calculate_delta (GtkWidget *widget,
float *x_scroll_delta,
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index 1c73a2f7f..233dd966c 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -38,6 +38,11 @@ G_BEGIN_DECLS
#define NAUTILUS_PREFERENCES_BACKGROUND_COLOR "preferences/background_color"
#define NAUTILUS_PREFERENCES_BACKGROUND_FILENAME "preferences/background_filename"
+/* Side Pane Background options */
+#define NAUTILUS_PREFERENCES_SIDE_PANE_BACKGROUND_SET "preferences/side_pane_background_set"
+#define NAUTILUS_PREFERENCES_SIDE_PANE_BACKGROUND_COLOR "preferences/side_pane_background_color"
+#define NAUTILUS_PREFERENCES_SIDE_PANE_BACKGROUND_FILENAME "preferences/side_pane_background_filename"
+
/* How wide the sidebar is (or how wide it will be when expanded) */
#define NAUTILUS_PREFERENCES_SIDEBAR_WIDTH "preferences/sidebar_width"
diff --git a/libnautilus-private/nautilus-icon-dnd.c b/libnautilus-private/nautilus-icon-dnd.c
index c83c51af9..dbcef85dd 100644
--- a/libnautilus-private/nautilus-icon-dnd.c
+++ b/libnautilus-private/nautilus-icon-dnd.c
@@ -520,13 +520,56 @@ nautilus_icon_container_selection_items_local (NautilusIconContainer *container,
return result;
}
+static GdkDragAction
+get_background_drag_action (NautilusIconContainer *container,
+ GdkDragAction action)
+{
+ /* FIXME: This function is very FMDirectoryView specific, and
+ * should be moved out of nautilus-icon-dnd.c */
+ GdkDragAction valid_actions;
+
+ if (action == GDK_ACTION_ASK) {
+ valid_actions = NAUTILUS_DND_ACTION_SET_AS_BACKGROUND;
+ if (g_object_get_data (G_OBJECT (eel_get_widget_background (GTK_WIDGET (container))), "is_desktop") == 0) {
+ valid_actions |= NAUTILUS_DND_ACTION_SET_AS_GLOBAL_BACKGROUND;
+ }
+
+ action = nautilus_drag_drop_background_ask (valid_actions);
+ }
+
+ return action;
+}
+
+static void
+receive_dropped_color (NautilusIconContainer *container,
+ int x, int y,
+ GdkDragAction action,
+ GtkSelectionData *data)
+{
+ action = get_background_drag_action (container, action);
+
+ if (action > 0) {
+ eel_background_receive_dropped_color
+ (eel_get_widget_background (GTK_WIDGET (container)),
+ GTK_WIDGET (container),
+ action, x, y, data);
+ }
+}
+
/* handle dropped tile images */
static void
-receive_dropped_tile_image (NautilusIconContainer *container, GtkSelectionData *data)
+receive_dropped_tile_image (NautilusIconContainer *container, GdkDragAction action, GtkSelectionData *data)
{
g_assert (data != NULL);
- eel_background_receive_dropped_background_image
- (eel_get_widget_background (GTK_WIDGET (container)), data->data);
+
+ action = get_background_drag_action (container, action);
+
+ if (action > 0) {
+ eel_background_receive_dropped_background_image
+ (eel_get_widget_background (GTK_WIDGET (container)),
+ action,
+ data->data);
+ }
}
/* handle dropped keywords */
@@ -915,6 +958,7 @@ nautilus_icon_container_receive_dropped_icons (NautilusIconContainer *container,
selected_item = container->details->dnd_info->drag_info.selection_list->data;
eel_background_receive_dropped_background_image
(eel_get_widget_background (GTK_WIDGET (container)),
+ context->action,
selected_item->uri);
return;
}
@@ -1357,7 +1401,6 @@ drag_data_received_callback (GtkWidget *widget,
break;
}
-
/* this is the second use case of this callback.
* we have to do the actual work for the drop.
*/
@@ -1371,14 +1414,16 @@ drag_data_received_callback (GtkWidget *widget,
context, x, y);
break;
case NAUTILUS_ICON_DND_COLOR:
- eel_background_receive_dropped_color
- (eel_get_widget_background (widget),
- widget, x, y, data);
+ receive_dropped_color (NAUTILUS_ICON_CONTAINER (widget),
+ x, y,
+ context->action,
+ data);
success = TRUE;
break;
case NAUTILUS_ICON_DND_BGIMAGE:
receive_dropped_tile_image
(NAUTILUS_ICON_CONTAINER (widget),
+ context->action,
data);
break;
case NAUTILUS_ICON_DND_KEYWORD: